sahajjain01

16.Generate Fibonacci series.

Aug 16th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.42 KB | None | 0 0
  1. //Program to generate Fibonacci series.
  2. #include<stdio.h>
  3. #include<conio.h>
  4.  
  5. void main()
  6. {
  7.     int i;
  8.     long a, b=0, c=1, d=1;
  9.  
  10.     clrscr();
  11.  
  12.     printf("Enter the number of terms of fibnoacci series to display: ");
  13.     scanf("%li", &a);
  14.     printf("The first %li terms of fibonacci series are: ", a);
  15.  
  16.     for(i=0;i<=a;i++) {
  17.         if(i <= 1)
  18.             d = i;
  19.         else {
  20.             d=b+c;
  21.             b=c;
  22.             c=d;
  23.         }
  24.         printf("%li ", d);
  25.     }
  26.     getch();
  27. }
Advertisement
Add Comment
Please, Sign In to add comment