Programming/Algorithm
Euclid
역시인생한방
2015. 2. 7. 18:39
////////////////////////////////////////////////////////////////////////////////
// Title : Euclid 알고리즘
// Author : 최민혁
// Revision : 2006. 9. 29 First implementation
////////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
int main(void)
{
int a, b, temp;
printf( "GCD를 구할 두 수를 입력하시오 : " );
scanf( "%d %d", &a, &b );
while( b != 0 )
{
if( b > a )
{
temp = b;
b = a;
a = temp;
}
temp = b;
b = a % b;
a = temp;
printf( "GCD( %d, %d )\n", a, b );
}
printf( "\nGCD( a, b ) = %d\n", a );
return 0;
}