CODE
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
int x,y,temp, remainder;
// read in the two integers
cout << endl;
cout << "Enter the first number (positive integer) : ";
cin >> x;
cout << "Enter the second number (positive integer) : ";
cin >> y;
//echo inputs
cout << "Input numbers are: " << x << " , " << y << endl;
if(x<y)
{ // exchange values of x and y
[color=#FF0000]Write three assignment statements in C++ that are
equivalent to the three statements given in the
pseudocode.[/color]
}
/* At this point we will always have x >= y */
[color=#FF0000]Initialize remainder.[/color]
[color=#FF0000]while ( )[/color]
{
[color=#FF0000]Write the loop expression and loop body code in C++. In C++, the expression (x % y) gives the remainder
after dividing x by y.[/color]
}
// display the result
cout << endl;
cout << "The GCD is: " << y << endl;
return (0); // terminate with success
I am having trouble with writing red.
This is the pseudocode which I have to go by to complete the code:
Declare x,y,temp, remainder as integer
Input x
Input y
If (x<y) then // exchange values of x and y
{
Set tmep=x
Set x=y
Set y=temp
}
End if
/* At this point we will always have x>=y*/
Set remainder=(x%y) //% is the remainder operator
While (remainder !=0)
{
Set x=y
Set y=remainder
Set remainder=(x%y)
}
End while
Output y // the final GCD will be in y