Wednesday, August 17, 2011

QUES 12 FIBONACCI SERIES


C LANGUAGE BOOK









 In a Fibonacci sequence the sum of two
successive terms gives the third  term. Following are the first
few terms of the Fibonacci sequence:
1   1   2   3   5   8   13   21   34   55   89...  

Example
1+1=2 third no
 2+1=3 Fourth no
3+2=5 Fifth no

WAP A PROGRAM TO PRINT FIBONACCI SERIES UPTO NUMBER ENTERED BY THE THE USER.

#include<stdio.h>

void main()
{
int x, i;
printf(" ENTER NUMBER UPTO WHICH FIBONACI SERIES HAS TO BE GENERATED___ ");
scanf("%d", &x);
printf(" \n FIBONNACI IS = ");

for(i = 1; i < x; i++)
      fibb(i);


getch();
}
 fibb(int n)
 {
   int a;

  {
   if(n == 0)
      a = 0;
   if(n == 1)
      a = 1;
   else
      a = fibb(n-1) + fibb(n-2);

  }
  printf("%d", a);
return;
}









C LANGUAGE BOOK

No comments:

Post a Comment