Hey there! The assignment is the the Fibonacci sequence except the user has to input how many elements they'd like to run for. We have to dynmically allocate memory this time, and build the array around it.
This is what I have so far, it seems to work but when I input large numbers the code starts returning negative numbers and going crazy....
#include <iostream>
usingnamespace std;
int main(){
unsignedint n;
cout << "please input the number of elements you would like this fibonacci sequence to run"<<endl;
cin>>n;
cout<<endl<<endl;
int* fib = newint[n];
for(int i=2; i<n; i++)
{
fib[0]=0;
fib[1]=1;
fib[i]=fib[i-1]+fib[i-2];
}
for(int i = 0; i < n; i++) cout << fib[i] << ' ';
delete[] fib;
system ("pause");
return 0;
}
See http://www.ideone.com/8MN2v . I ran it there with input = 20 elements and seems to work OK. How large is large for you? Also note that I corrected the code a bit: Lines 14 and 15 were taken out of the loop.