prepare a c++ program which will compute Fibonacci numbers. the resulting answer must be of unsigned long
The input is the position of the requested number in the sequence of Fibonacci numbers.
turn in two versions of your program, one based on iteration (loop)and the other on recursion.
in addition to listing of the two version, please answer:
With your development platforms, what is the range of values allowed for unsigned long?
list input you testing?
if your resulting answer were specified to be of type int, would your test data set change? if so, what changes would you make and why?
#include <iostream>
void recursion(int x);
void loop(int x);
int main()
{
recursion(10);
loop(10);
return 0;
}
void recursion(int x)
{
if(x > 0)
{
std::cout << "This is recursion. x = " << x << std::endl;
return recursion(x - 1);
}
}
void loop(int x)
{
for(int i = 0; i < x; ++i)
std::cout << "This is a loop! i = " << i << std::endl;
}
This is recursion. x = 10
This is recursion. x = 9
This is recursion. x = 8
This is recursion. x = 7
This is recursion. x = 6
This is recursion. x = 5
This is recursion. x = 4
This is recursion. x = 3
This is recursion. x = 2
This is recursion. x = 1
This is recursion. x = 0
This is a loop! i = 0
This is a loop! i = 1
This is a loop! i = 2
This is a loop! i = 3
This is a loop! i = 4
This is a loop! i = 5
This is a loop! i = 6
This is a loop! i = 7
This is a loop! i = 8
This is a loop! i = 9