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

0 comments:

Post a Comment