Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

CSC112 Spring 2016 Examples

2370 views
1
#include <iostream>
2
3
using namespace std;
4
5
6
int main()
7
{
8
int n;
9
unsigned long int f1=1, f2=1, f;
10
11
cout << "How many fibbonacci numbers would you like me to compute? ";
12
13
cin >> n;
14
15
for(int i=0; i<n; i++) {
16
if(i<2) {
17
f = 1;
18
} else {
19
f = f1 + f2;
20
}
21
22
f2 = f1;
23
f1 = f;
24
25
cout << f << ' ';
26
cout.flush();
27
}
28
29
cout << endl;
30
31
return 0;
32
}
33
34
35