Fibonacci in C++

It is a pattern when you add the 2 previous numbers together and to get the next number. And so on.

1. 1. 1. 2. 3. 5. 8. 13. 21. 34. 55. 89. 144. And so on.


#include < iostream. h >
using namespace std;
int main()
{
int number[30] = {1, 1, 0};
int total;
for(int i = 2; i < 30; i++)
{
number[i] = number[i - 1] + number[i - 2];
cout << number[i] << endl;
}
return 0;
}

0 comments:

Post a Comment