You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
580 B
C++

Fig02_10.cpp - Euclid's algorithm, with a test program
#include <iostream.h>
/* START: Fig02_10.txt*/
long gcd( long m, long n )
{
/* 1*/ while( n != 0 )
{
/* 2*/ long rem = m % n;
/* 3*/ m = n;
/* 4*/ n = rem;
}
/* 5*/ return m;
}
/* END */
// Test program
int main( )
{
cout << "gcd( 45, 35 ) = " << gcd( 45, 35 ) << endl;
cout << "gcd( 1989, 1590 ) = " << gcd( 1989, 1590 ) << endl;
return 0;
}