Prerequisite:
Fibonacci series:
nth number in series = (n-1)th Number + (n-2)th Number
0, 1 ,1 ,2 ,3 ,5 ,8 ,13 ,21 ,34 ,55 ,89……….
Program
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#include <stdio.h> int main() { long int i, numcount,nextnumcount; long int numcount1 = 0, numcount2 = 1; printf("Enter the last number of Fibonacci series: "); scanf("%ld", &numcount); printf("Fibonacci Series: \n"); while(numcount1<numcount) { printf("%ld, ", numcount1); nextnumcount = numcount1 + numcount2; numcount1 = numcount2; numcount2 = nextnumcount; } return 0; } |
1 2 3 4 |
Output: Enter the last number of Fibonacci series:100 Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, |