Fibonacci Series


write a C program to print Fibonacci Series.


 #include  <stdio.h>

void main()
{
  long  a=1 ,b=1 , c ;
  int  i , n ;
  printf("Enter n: ") ;
  scanf("%d" , &n) ;
  printf("Fibonacci series is as shown: \n") ;

  if(n==1)
    printf(" %ld" , a) ;
  else if(n==2)
    printf(" %ld \n%ld" , a , b) ;
  else if(n>2)
  {
     printf("%ld \n\n%ld\n" , a , b) ;
     for(i=1 ; i<=n-2 ; i++)
     {
       c=a+b ;
       printf("  \n%ld\n" , c) ;
       a=b ;
       b=c ;
     }
  }
}

Output :

Output