#include <iostream>
using namespace std;
unsigned long long Fibonacci(int n) {
if (n <= 1)
return n;
else
return Fibonacci(n - 1) + Fibonacci(n - 2);
}
void PrintFibonacci(int n) {
for (int i = 0; i < n; ++i) {
cout << Fibonacci(i);
if (i != n - 1) {
cout << ", ";
}
}
}
int main() {
int numberOfTerms = 20;
cout << "Fibonacci series for " << numberOfTerms << " terms: " << endl;
PrintFibonacci(numberOfTerms);
return 0;
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter