Answer to Question #21189 in C++ for aa aa

Question #21189
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();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS