Turbo C - Fibonacci Series
The logic for fibonacci series very simple. It starts with 0 and 1. The next subsequent term is the sum of the previous two terms.
Source Code
// Program for Fibonacci Number
#include <stdio.h>
void main()
{
int f1 = 0, f2 = 1, f3, n;
printf("Program for Fibonacci Series\n");
printf("Enter the maximum number for Fibonacci Series: ");
scanf("%d", &n);
printf("\nPrinting Fibonacci Series from 0 - %d\n", n);
printf("%d\n%d\n", f1, f2);
while(1)
{
f3 = f1 + f2;
if(f3 > n)
break;
printf("%d\n", f3);
f1 = f2;
f2 = f3;
}
}
Output
Program for Fibonacci Series
Enter the maximum number for Fibonacci Series:
Printing Fibonacci Series from 0 - 1000
0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
|