-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfibonacci-sequence.cpp
52 lines (45 loc) · 1.15 KB
/
fibonacci-sequence.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
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
This piece of code was made by Grzegorz Skornowicz
You can contact me at [email protected]
You can clone this code from GIT repository under link:
This software is free to use by anybody
May The Force Be With You !!!
*/
#include <iostream>
#include <iomanip>
using namespace std;
void fibnumber(int n)
{
long double *p;
p = new long double[n];
if (n == 0) cout << "0";
else if (n == 1) cout << "1";
else
{
p[0] = 0;
p[1] = 1;
for (int i = 2; i <= n; i++)
{
p[i] = p[i - 1] + p[i - 2];
}
for (int i = 0; i <= n; i++)
{
cout << i << " - " << p[i] << "\n";
}
}
//delete [] p; // FIX dynamic allocation heap error after delete of array???
}
int main()
{
int n;
cout << "Fibonacci number function to n place" << endl;
cout << "This piece of code was written by Grzegorz Skornowicz index nr 5899" << endl;
cout << "=============================================================" << endl;
cout << "please type in n number, n marks how many fibonnaci numbers you want to get." << endl;
cin >> n;
cout << fixed;
cout << setprecision(0);
fibnumber(n);
system("pause");
return 0;
}