C Online Compiler
Example: C program to generate the Fibonacci series using iteration
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// 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; }
8
Output
Clear
ADVERTISEMENTS