‘C’ program to display n terms of the Fibonacci series.

C File =>


/* Write a ‘C’ program to display n terms of the Fibonacci series. */

#include<stdio.h>
int main() 
{
      int n,i,a=0,b=1,c;
 
      printf("\n Enter value of n : ");
      scanf("%d",&n);
 
      if(n==1)
         printf("\n %d",a);
      else if(n==2)
         printf("\n%d\t%d",a,b);
      else if(n>2)
      {
          printf("\n%d\t%d\t",a,b);
          for(i=3;i<=n;i++)
          {
              c=a+b;
              printf("%d\t",c);
              a=b;
              b=c;
          } //end for
       }
 
       return 0;
}

Comments

Popular posts from this blog

Write a program to allocate memory dynamically for n integers. Accept the elements and calculate their sum and average

C program to accept names of n cities and search for city named “Pune”.