// to compile: g++ fib1.cpp // // to compute the 50th number in the Fibonacci number sequence // to run: ./a.out 50 #include #include using namespace std; long long fib(int n) { if (n <= 1) return 1; else if (n == 2) return 1; else return fib(n-1) + fib(n-2); } int main(int argc, char* argv[]) { if (argc == 1) cout << "fib(10) = " << fib(10) << "\n"; else cout << "fib(" << atoi(argv[1]) << ") = " << fib(atoi(argv[1])) << "\n"; return 0; }