Create a function int Fibonacci(int n), that will calculate the Fibonacci number.
Use the parameters in main, int argc, char *argv[].
1
Expert's answer
2012-12-25T10:10:51-0500
#include <iostream> #include <conio.h>
using namespace std;
int Fibonacci(int n) { int curr = 1; int prev = 1; int tmp;
for (int c = 3; c <= n; c++) { tmp = curr; curr += prev; prev = tmp; } return curr; }
void main(int argc, char* argv[]) { if (argc != 2) return; int n = atoi(argv[1]); cout << "Fibonacci number for N = " << n << " is " << Fibonacci(n) << endl; getch(); }
Comments
Leave a comment