62 565
Assignments Done
99%
Successfully Done
In June 2018

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[].
Expert's answer
#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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions