Header Ads

08 - WAP to Print the Fibonacci Series in C

This Program prints the Values of Fibonacci Series till the desired User Value.

/*we have to print the greatest fibonacci no and the fibonacci series*/
#include 
int main()
{
   int idx = 0, first = 0, second = 1, m , fn = 1 , old ;
   //enter the number
   printf("Enter the Number : ");
   scanf("%d", &m);
   //this will print 0
   printf("%d\t",first);   
   for ( idx = 0; fn <= m; idx++)
   {
      //it will print 1
      printf("%d\t",fn);
      //it will check wheather less or not from the users no
      if ( fn <= m )
      {
         old = fn;
         fn = first + second;
         first = second;
         second = fn; 
      }
   }
 //it will go to the new line
 printf("\n");
 printf("Largest Number in the Series is : %d\n",old);
 return 0;
}

Program Output: 

No comments