I am trying to make a Euclid’s Algorithm with Loop While process.
I need to get the program to:
input: smaller number followed by larger & output: greatest common divisor
1. Read two numbers
2. print out both numbers
3. REMAINDER = remainder of LARGER/SMALLER.
4. Loop while REMAINDER is not zero:
a. Set LARGER to SMALLER.
b. Set SMALLER to REMAINDER.
c. REMAINDER = remainder of LARGER/SMALLER.
d. End loop.
5. Print ‘Greatest common divisor is,’SMALLER.
6. end the program.....
So far I have:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
#include <iostream>
using namespace std;
int main()
{
int a;
int b;
int remainder;
cout << "Please select an integer for a\n"; // value a must less than value b
cin >> a; // select a value
cout << "Please select an integer for b\n"; // value b must be greater than a
cin >> b; // select a value greater than value a
cout << "The smaller number is: " << a; // outputs the smaller value
cout << "The larger number is: " << b; // outputs the greater value
remainder = a % b
while (remainder != 0)
{
b = a
a = remainder
remainder = b/a
}
cout << endl;
cout << "Greatest common divisor is: " << a;
return 0;
}
|
all my compiler is telling me is that line 20 has
[error: expected ';' before 'while']