//============================================================================
// 제출일 : 2005. 4. 12
// 작업환경 : Windows XP SP1, VC++ 6.0, Pentium4
// 연습문제 9-67
//============================================================================
#include <iostream.h>
int get_gcd(int a, int b); //recursive fuction
int main()
{
int gcd;
int a, b;
cout << "input factor A : ";
cin >> a;
cout << "input factor B : ";
cin >> b;
gcd = get_gcd(a, b);
cout << "gcd is " << gcd << endl;
cout << "lcm is " << a*b/gcd << endl;
return 0;
}
int get_gcd(int a, int b) //get gcd by recursive
{
if (a ==0 || b == 0)
return a+b;
else if (a >= b)
return get_gcd(a%b, b);
else
return get_gcd(b%a, a);
};
'Studies > A Structured Approach Using C++' 카테고리의 다른 글
Project 4-41 Create customers' bills 영수증 발행 (0) | 2008.08.23 |
---|---|
Project 4-40 Random number 랜덤 (0) | 2008.08.23 |
Project 4-39 Temperature convertor : Fathrenheit VS Centigrade 온도변환기 : 화씨 섭씨 (0) | 2008.08.23 |
Project 4-38 Compute the interest and print the balance (0) | 2008.08.23 |
Project 4-37 Prepare a payroll earnings statement (0) | 2008.08.23 |