C++ Codes
Algorithms
Algorithm Analysis in C++
Beginners
Code Snippets
Graphics
Data Structures
File Manipulation
Games
Mathematics
Miscellaneous
Visual C++ Library
C++ > Data Structures and Algorithm Analysis in C++ sample source codes
Fig02_10.cpp - Euclid's algorithm, with a test program
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; }
Privacy Policy
|
Link to Us
|
Links