pages

Wednesday, 14 April 2021

Fibonacci series using recursion in c -programming | c language

Fibonacci series using recursion in c-program | Fibonacci series c-language recursion.

Fibonacci series is a series of the number where the third term is the sum of the previous two terms 

for example: 0,1,1,2,3,5,8,.....

The next number is found by the adding up the two numbers before it. The first two term are zero and one respectively.


#include<stdio.h>
#include<conio.h>
int fun(int x);
void main()
{
   int n,i;
   printf("enter the number\n");
   scanf("%d",&n);
   for(i=1;i<=n;i++)
      printf("%d ",fun(i));
   getch();
}
int fun(int x)
{
         if(x==1|| x==2)
                  return(1);
         return(fun(x-1)+fun(x-2));
}


output:- 






For more c-programming example:-



  










No comments:

Post a Comment