View Single Post
Old Aug 24th, 2005, 1:16 PM   #8
melee28
Newbie
 
melee28's Avatar
 
Join Date: Aug 2005
Location: Orlando
Posts: 11
Rep Power: 0 melee28 is on a distinguished road
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.
melee28 is offline   Reply With Quote