programming-examples/c++/Others/Fig02_10.cpp - Euclid's algorithm, with a test program.cpp

25 lines
580 B
C++
Raw Normal View History

2019-11-15 12:59:38 +01:00
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;
}