Monday, July 30, 2018

C program for fibonacci series

Fibonacci series?
First two numbers of the fibonacci series is 0 and 1. From third number on words , the series eill be the sum of previous two numbers.



#include <stdio.h>
int main()
{
   int f1=0, f2=1, fib_ser, cnt=2, lmt;

   printf("Please enter the limit of the Fibonacci series :");
   scanf("%d",&lmt);
   printf("\nFibonacci series is: \n%d \n%d \n",f1,f2);

   while (cnt < lmt)
   {
      fib_ser=f1+f2;
      cnt++;
      printf("%d\n",fib_ser);
      f1=f2;
      f2=fib_ser;
   }
   return 0;
}

Output:

No comments:

Post a Comment

C program for find square value

This is an example of how to find square value of a number using function.  #include<stdio.h> float square ( float x ); int ma...