Computer Science, asked by LoveDose01, 4 months ago

Write a c program to find Fibonacci series using recursion.

Answers

Answered by prakashkkaladindi
2

Answer:

Fibonacci Series using recursion in C

#include<stdio.h>

void printFibonacci(int n){

static int n1=0,n2=1,n3;

if(n>0){

n3 = n1 + n2;

n1 = n2;

n2 = n3;

printf("%d ",n3);

Answered by pratyush15899
9

Explanation:

#include<stdio.h>

void printFibo(int );

int main()

{

int k, n; long int i = 0, j = 1;

printf("Enter the length of the Fibonacci series: ");

scanf("%d", &n);

printf("\n\nfirst %d terms of Fibonacci series are:\n\n\n",n);

printf("%d ", 1);

printFibo(n);

return 0;

}

void printFibo(int aj)

{ static long int first = 0, second = 1, sum;

if(aj > 1)

{ sum = first + second; first = second; second = sum;

printf("%ld ", sum); printFibo(aj-1); // recursive call

}

else

{

// after the elements, for line break

printf("\n\n\n");

}

}

Output:

Enter the length of the Fibonacci series : 7

First 7 terms of Fibonacci series are :

1 1 2 3 5 8 13

:))

Similar questions