View Single Post
Old Aug 24th, 2005, 1:39 PM   #9
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Sadly, your expectations don't matter a dam' to the machine, only what you tell it to do. Did you consider running the numbers, yourself, as below, and seeing what happens?
  printf("%2d", fib1);   // print 0     Output:	0
  printf("%2d", fib2);	 // print 1                 0 1
  printf("%2d", fib3);	 // print 1                 0 1 1
  temp = fib1 + fib2;	// temp = 1
  fib1 = fib2;             // fib1 = 1
  fib2 = fib3;             // fib2 = 1
  fib3 = temp;		 // fib3 = temp = 1
  
  
  printf("%2d", fib3);  // print fib3 (1)          0 1 1 1
  
  temp = fib1 + fib2;	// temp = 2
  fib1 = fib2;             // fib1 = 1
  fib2 = fib3;             // fib2 = 1
  fib3 = temp;           // fib3 = 2
  
  
  printf("%2d", fib3);  // print fib3 = 2          0 1 1 1 2
  
  temp = fib1 + fib2;	// temp = 2
  fib1 = fib2;             // fib1 = 1
  fib2 = fib3;             // fib2 = 2
  fib3 = temp;           // fib3 = 2
  
  
  printf("%2d", fib3);  // print fib3 (2)           0 1 1 1 2 2
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote