// Chap 2, p 91
int IterativeRabbit(int N)
// Iterative solution to the rabbit problem.
{
// initialize base cases:
int Previous = 1; // initially Rabbit(1)
int Current = 1; // initially Rabbit(2)
int Next = 1; // result when N is 1 or 2
// compute next Rabbit values when N >= 3
for (int I = 3; I <= N; ++I)
{ // Current is Rabbit(I-1), Previous is Rabbit(I-2)
Next = Current + Previous; // Rabbit(I)
Previous = Current; // get ready for
Current = Next; // next iteration
} // end for
return Next;
} // end IterativeRabbit
// ******SAMPLE MAIN PROGRAM******
main()
{
cout << "Iterative Rabbit: " << endl;
cout << IterativeRabbit(1) << " " << IterativeRabbit(2) << " ";
cout << IterativeRabbit(3) << " " << IterativeRabbit(4) << " ";
cout << IterativeRabbit(5) << " " << IterativeRabbit(6) << " ";
cout << "\n";
return 0;
}
               (
geocities.com/siliconvalley/program/2864/ds)                   (
geocities.com/siliconvalley/program/2864)                   (
geocities.com/siliconvalley/program)                   (
geocities.com/siliconvalley)