~cpp #include <stdio.h> int Get_GCM(int , int ); void Get_x_y(int, int, int*, int*, int ); void main() { int input_a, input_b; while (1) { int x=0, y=0, gcm=0; printf ("두 숫자를 입력해 주세요.(0,0)은 정지\n>>"); scanf ("%d%d",&input_a,&input_b); if (0==input_a && 0==input_b) break; gcm=Get_GCM(input_a, input_b); Get_x_y(input_a, input_b, &x, &y, gcm); printf ("결과 : x=%d\ty=%d\tGCM=%d\n",x,y,gcm); } } void Get_x_y(int number_a, int number_b, int* x, int* y, int gcm) { int *temp_large, *temp_small, temp_plus=1; if (number_a>number_b) { temp_large=x; temp_small=y; } else { temp_large=y; temp_small=x; } while(number_a*(*x)+number_b*(*y)!=gcm) { if (temp_plus>0 && number_a*(*x)+number_b*(*y)>gcm) { *temp_large=0; temp_plus=-1; } else if (temp_plus<0 && number_a*(*x)+number_b*(*y)<gcm) { *temp_large=0; temp_plus=1; if (*temp_small>0) *temp_small*=-1; else *temp_small=*temp_small*(-1)+1; } else *temp_large+=temp_plus; } } int Get_GCM(int number_a, int number_b) { int temp; while (temp=number_a%number_b) { number_a=number_b; number_b=temp; } return number_b; }