C++ Program to Print Fibonacci Series using For Loop
Write C++ Program to Print Fibonacci Series using For Loop
// CPP Program to Print Fibonacci Series using For Loop #include <iostream> using namespace std; int main() { int n, i, f1, f2, f3; cout << "Enter the number :--> "; cin >> n; f1 = 0; f2 = 1; cout << f1 << " " << f2 << " "; for(i = 1; i < n; i++) { f3 = f1 + f2; cout << f3 << " "; f1 = f2; f2 = f3; } return 0; }
Output:
Enter the number :--> 5
0 1 1 2 3 5