#include <iostream> #include<cmath> #include<ctime> #include<string> #include <iomanip> #include <fstream> using namespace std; int main() { int f1 = 0, f2 = 1; int nextTerm = 0; for (int i = 1; i < 10; i++) { //print first 2 numbers if (i == 1) { cout << f1<<" "; continue; } if (i == 2) { cout << f2 << " "; continue; } nextTerm = f1 + f2; f1 = f2; //make f2 = the next term f2 = nextTerm; cout << nextTerm<<" "; } }
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