The following algorithm is designed to print the beginning of what is known as the
Fibonacci sequence. Identify the body of the loop. Where is the initialization step for the
loop control? The modification step? The test step? What list of numbers is produced?
Last ← 0;
Current ← 1;
while (Current < 100) do
(print the value assigned to Current;
Temp ← Last;
Last ← Current; and
Current ← Last + Temp)
Here is program:
int main()
{
int Last;
int Current = 1;
int Temp;
cin >> Last;
cin >> Temp;
Current = Last + Temp;
while (Current < 100)
{
cout << Current << endl;
Current++;
}
}
Comments
Leave a comment