-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15.3 (C++) Calculate Fibonacci series of the given values by using array.cpp
More file actions
64 lines (47 loc) · 1.48 KB
/
15.3 (C++) Calculate Fibonacci series of the given values by using array.cpp
File metadata and controls
64 lines (47 loc) · 1.48 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/// Calculate Fibonacci series of the given values by using array
/*
Fibonacci series,
Let, initial1st_no=0, 2nd_no=1 [first & second number are always constant]
Formula:
Fibonacci Value (n) = Summation of previous 2 values
Example:
Fibonacci Value (0) = 1st_no = 0
Fibonacci Value (1) = 2nd_no = 1
Fibonacci Value (2) = 1st_no + 2nd_no = 0+1 = 1 (3rd_no)
Fibonacci Value (3) = 2nd_no + 3rd_no = 1+1 = 2 (4th_no)
Fibonacci Value (4) = 3rd_no + 4th_no = 1+2 = 3 (5th_no)
Fibonacci Value (5) = 4th_no + 5th_no = 2+3 = 5 (6th_no)
Fibonacci Value (5) = 4th_no + 5th_no = 3+5 = 8 (7th_no)
*/
#include <iostream>
using namespace std;
int main()
{
int fibo[100];
int n, i, count=0;
fibo[0]=0;
fibo[1]=1;
cout<<" Enter the Fibonacci value (n): ";
cin>>n;
// Calculate Fibonacci Series
for(i=2; i<n; i++){
fibo[i] = fibo[i-1] + fibo[i-2];
}
//Showing Fibonacci Series
cout<<endl;
for(i=0; i<n; i++){
cout<<" Fibonacci Value ("<<count<<"): "<<fibo[i]<<endl;
count++;
}
return 0;
}
/* ===== Output / Result:
Input:
Enter the Fibonacci value (n): 5
Output:
Fibonacci Value (0): 0
Fibonacci Value (1): 1
Fibonacci Value (2): 1
Fibonacci Value (3): 2
Fibonacci Value (4): 3
*/