/* ************************************************************************** * Program name : 030_Greater_common_factor (Recursion Version 1.00) * * Author : Duck Wong * * Language : C / C++ * * Compiler : Boodshed Dec-C++ compiler Ver 3.95 * * Computer : PII350 * * O/S : Windows 98 * ************************************************************************** * Version 1.00 : 2000/06/12 - first version * ************************************************************************** * Description : (a) Input the size of the checkerboard pattern * * (b) Output the checkerboard pattern * * (c) Try again ? * ************************************************************************** */ #include #include void gcf(unsigned long N1, unsigned long N2) { if ((N1 % N2) != 0) // Note(1) gcf(N2,N1 % N2); else cout << N2; // Note(2) } int main() { // part 1 : declaration unsigned long Num_1, Num_2; char Again; do { // part 2 : Asking two numbers cout << "\nPlease enter 2 integer numbers : "; cin >> Num_1 >> Num_2; // part 3 : Calculation and output result cout << "\nGCF = "; gcf(Num_1,Num_2); cout << "\n" << endl; // part 4 : try another numbers ? cout << "\aTry another set of numbers (Y/N) : "; cin >> Again; cout << "\n"; } while (Again=='Y' || Again=='y'); cout << "\n" << endl; system("PAUSE"); return 0; } /* Notes (1) How to find the GCF : Example (a) 60 , 12 -> GCF = 12 since (60 % 12) = 0 (b) 60 , 48 -> (60 % 48) = 12 (no equal to zero), then call the gcf function again with the new values 48 and 12. GCF = 12 since (48 % 12) = 0 (2) Can not use "return" statement. Display the value of the GCF directly to the screen. */