C program to generate the fibonacci series using iteration
ADVERTISEMENTS
C program to generate the Fibonacci series using iteration, there are you will learn how to make a C program to find the fibonacci series of any number of terms.
Before making this program you have to knowledge of the Fibonacci series concepts to complete out this.
Formula to find the Fibonacci of any number of terms
The Fibonacci series is: 1, 2, 3, 5, 8, 13, 21, 34
Let us understand this through a c program:
// C program to generate the Fibonacci series using iteration
#include <stdio.h>
int main() {
int x, i, t1 = 1, t2 = 2, nt;
// x denotes number of terms
// t1 denotes term 1
// t2 denotes term 2
// nt denotes next term
printf("Enter the number of terms to generate the fibonacci series::\n");
scanf("%d", &x);
printf("Fibonacci Series:: ");
for (i = 1; i <= x; ++i) {
printf("%d, ", t1);
nt = t1 + t2;
t1 = t2;
t2 = nt;
}
printf("\n");
return 0;
}
Output
Enter the number of terms to generate the fibonacci series::
8
Fibonacci Series:: 1, 2, 3, 5, 8, 13, 21, 34,
8
Fibonacci Series:: 1, 2, 3, 5, 8, 13, 21, 34,