#include <iostream> using namespace std; int fib(int n) { int t0 = 0, t1 = 1, s=0, i; if (n<=1) return n; else for(i=2;i<=n;i++) { s = t0 + t1; t0 = t1; t1 = s; } return s; } int main() { cout << fib(9); 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