C++ Online Compiler
Example: C++ program to generate the Fibonacci series using iteration
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// C++ program to generate the Fibonacci series using iteration #include <iostream> using namespace std; 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 cout << "Enter the number of terms to generate the Fibonacci series::\n"; cin >> x; cout << "Fibonacci Series:: "; for (i = 1; i <= x; ++i) { cout << t1 << ", "; nt = t1 + t2; t1 = t2; t2 = nt; } cout << "\n"; return 0; }
8
Output
Clear
ADVERTISEMENTS