Hello guys,
I’m doing a beginner course in C++.
I was given as an exercise to display “Binocchi” (spelled right?) numbers using arrays.
(1, 1+1=2, 1+2=3, 2+3=5, 5+3=8, 5+8=13, etc.)
(hence: 1 1 2 3 5 8, etc.)
After long consideration I got this:
Code:
#include <iostream.h>
int main()
{
int myarray[5];
myarray[0] = 1;
myarray[1] = 1;
for(int i = 2; i<5; i++)
{
myarray[i] = myarray[i-1] + myarray[i-2];
}
cout << myarray << endl;
return 0;
}
As far my logic goes the array should display 1 1 2 3 5 8.
I’m still not familiar with these arrays, for loops, etc. I mean, I’m having fun but its getting a bit frustrating.
Also would be nice if I could get a user to enter a number for the iterations.
If someone wants to shed some light. Thanks.