2011. 8. 29. 01:21

//2011 08 28
//유클리드 알고리즘 구현하기
//Daun..
//I_co@IGRUS

#include <iostream>
using namespace std;

void swap(int,int);
int GCD(int,int);

int main()
{
 int num1=0, num2 = 0;

 cout << "두개의 숫자를 입력해 주세요\n";
 cin >> num1>>num2;

 cout << GCD(num1,num2);
 return 0;
}
void swap(int *a, int *b)
{
 int temp;
 temp = *a;
 *a = *b;
 *b = temp;
}
int GCD(int num1, int num2)
{
 if(num1<num2)
  swap(num1,num2);

 if(num2)
 {
  GCD(num2, num1-num2);
 }
 else
 {
  return num1;
 }
}

 

'Code > c/c++' 카테고리의 다른 글

[C++]Game of Snake.  (0) 2011.09.03
[C++]poker  (0) 2011.09.03
[C++ Code]Swap  (0) 2011.07.28
[C++ Code]주소값출력하기  (0) 2011.07.28
[C++ Code]재귀함수  (0) 2011.07.28
Posted by I_co