Pages

Saturday, 23 February 2019

Program to illustrate Fibonacci series using recursion

 Program to illustrate Fibonacci series using recursion
//fibonacci series of a given number using recursion
#include<stdio.h>
int s,x,a,b,r;  // global declaration
int fib(int); // function declaration
int main()
{
 int i,n,rev;
 printf("enter any number:\n");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  s=fib(i); // calling function
  printf("%d\t",s);
 }
}

int fib (int x)  // called function
 {
  int a,b;
  if(x <= 1)
    return (x);  // base case
  else
  {
   a=fib(x-1);
   b=fib(x-2);
   return (a+b); // recursive calling
  }
}
output:

No comments:

Post a Comment

Programs in turboc3 : Files

File Handling in C File Handling concept in C language is used for store a data permanently in computer. Using this concept we can store our...