main()
for
do while
how_many
//Greatest common divisor program. #include <iostream.h> //input/output library #include <assert.h> //for errors int gcd(int m, int n){ //function definition int r; //declaration of remainder while (n != 0) { //not equal r = m % n; //modulus operator m = n; //assignment n = r; } //end while loop return m; //exit gcd with value m }
int main(){ int x, y, g; cout << "\nPROGRAM gcd C++"; do { cout << "\nEnter two integers: "; cin >> x >> y; assert(x * y != 0); //precondition on gcd cout << "\nGCD(" << x << "," << y << ") = " << (g = gcd(x, y)) << endl; //postcondition on g assert(x % g == 0 && y % g == 0); } while (x != y); return 0; }