~cpp #include <stdio.h> void main() { int x2, y2, x, y,remainder; printf("두 숫자 입력 (ex| 5 6):"); scanf("%d %d", &x, &y); x2 = x; y2 = y; //y값을 y2를 이용해 사용. if(y2 < x2) { int temp; temp = x2; x2 = y2; x2 = temp; } // 유클리드 호제법 while(y2 != 0){ remainder = x2 % y2; // x2= 나눠질 값. y2= 나누는 값. remainder= 나머지. x2 = y2; y2 = remainder; } printf("x = %d, y = %d\n GCD is %d", x, y, x2); }
~cpp #include <stdio.h> void Eu_clidian(int x, int y); void main() { int x, y; printf("두 숫자 입력 (ex| 5 6):"); scanf("%d %d", &x, &y); Eu_clidian(x, y); } void Eu_clidian(int x, int y) { int x2, y2, remainder; x2 = x; y2 = y; while(y2 != 0){ // 유클리드 호제법 remainder = x2 % y2; x2 = y2; y2 = remainder; } printf("The GCD of %d and %d is %d\n", x, y, x2); }