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;
}

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 < stdio.h >

int main()
{
int i, x;
int a = 0;
int b = 1;

printf("%i\n%i\n", a, b);
for(i = 2; i < 100; i++)
{
x = a;
a = b;
b = x + b;
printf("%i\n", b);
}

return 0;
}