C Programming Tutorial

Advertisements

Write program to display fibonacci series in C



       #include<stdio.h>
       #include<conio.h>
       void main()
       {
              int a=0,b=1,i,sum,n;
              clrscr();

              printf("\nEnter any number : "); 
              scanf("%d",&n); 
              
              printf("\nFibonacci series : ");
              for(i=1;i<=n;i++)
              {
                     sum = a + b;
                     printf("%d ",sum);
                     a = b;
                     b = sum;                     
              }

              getch();
       }

   Output : 

              Enter any number : 10
              Fibonacci series : 1 2 3 5 8 13 21 34 55 89




Advertisement