As far as I can tell, this looks like it should work.
The first two elements are set to 1 (I am ignoring the first 0). The for loop is supposed to loop through the array, and since the fibonacci numbers are equal to the sum of the two preceeding numbers, I want to add them, then display them.
The output is all 2s, and I am not quite sure why.
Note: I am not looking directly for the answer, but a way that I can figure this out myself.
//Fibonacci sequence
#include <stdio.h>
int main(void) {
int fib_numbers[40] = {1, 1}, i;
for(i = 1; i < 40; i++) {
fib_numbers[i] = fib_numbers[i] + fib_numbers[i - 1];
printf("\t%d\n", fib_numbers[i]);
}
return 0;
}