-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fibonacci_array.cpp
39 lines (26 loc) · 918 Bytes
/
Fibonacci_array.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
using namespace std;
int main()
{
int arr[10],num;
cout<<"Enter the number of Fibonacci Terms required:\n";
cin>>num;
arr[0] = 0;
arr[1] = 1;
int Result;
cout<<"Fibonacci Series of "<<num<<" numbers: ";
// Here we are printing 0th and 1st terms
cout << arr[0] << ", " << arr[1] << ", ";
for(int i = 2; i < num; i++){
Result = arr[0] + arr[1];
arr[0] = arr[1];
arr[1] = Result;
cout << Result << ", ";
}
return 0;
}