fibonacci series using iterative method

Solutions on MaxInterview for fibonacci series using iterative method by the best coders in the world

showing results for - "fibonacci series using iterative method"
Genna
03 Jun 2019
1#include <iostream>
2using namespace std;
3void fib(int num) {
4   int x = 0, y = 1, z = 0;
5   for (int i = 0; i < num; i++) {
6      cout << x << " ";
7      z = x + y;
8      x = y;
9      y = z;
10   }
11}
12int main() {
13   int num;
14   cout << "Enter the number : ";
15   cin >> num;
16   cout << "\nThe fibonacci series : " ;
17   fib(num);
18   return 0;
19}