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
//recurrence relationship of the Fibonacci Sequence
6
unsigned long int fib(unsigned long int x)
7
{
8
if(x >= 2) {
9
return fib(x-2) + fib(x-1);
10
} else {
11
return 1;
12
}
13
}
14
15
int
16
main() {
17
int count;
18
19
//ask for the number of fibonacci numbers wanted
20
cout << "How many fibonacci numbers would you like me to compute? ";
21
cin >> count;
22
23
for(int i=0; i<count; i++) {
24
cout << fib(i) << ' ';
25
cout.flush();
26
}
27
28
cout << endl;
29
30
return 0;
31
}
32
33