So then what you guys are saying is...that the code I provided should work (albeit only for the first four numbers)? The problem I'm having is...it doesn't. I went ahead and copy/pasted for clarity, but the results I'm getting are as follows:
0 1 1 1 2 2 3 4 5 7
So the problem seems to lie in some fundamental aspect that I missed. Here is the updated code.
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
/*Local Definitions*/
int fib1 = 0;
int fib2 = 1;
int fib3 = 1;
int temp = 0;
/*Statements*/
printf("%2d", fib1);
printf("%2d", fib2);
printf("%2d", fib3);
temp = fib1 + fib2;
fib1 = fib2;
fib2 = fib3;
fib3 = temp;
printf("%2d", fib3);
temp = fib1 + fib2;
fib1 = fib2;
fib2 = fib3;
fib3 = temp;
printf("%2d", fib3);
temp = fib1 + fib2;
fib1 = fib2;
fib2 = fib3;
fib3 = temp;
printf("%2d", fib3);
temp = fib1 + fib2;
fib1 = fib2;
fib2 = fib3;
fib3 = temp;
printf("%2d", fib3);
temp = fib1 + fib2;
fib1 = fib2;
fib2 = fib3;
fib3 = temp;
printf("%2d", fib3);
temp = fib1 + fib2;
fib1 = fib2;
fib2 = fib3;
fib3 = temp;
printf("%2d", fib3);
temp = fib1 + fib2;
fib1 = fib2;
fib2 = fib3;
fib3 = temp;
printf("%2d", fib3);
printf("\n");
system("PAUSE");
return 0;
}
I guess my question is....Where did I screw up?
melee28
p.s. I know this isn't effective or pretty coding..just bear with me while I learn.