유클리드 알고리즘 구현할려고하는데요...ㅠㅠ
볼1매그녀
유클리드 알고리즘을 구현할라고하는데여
최대공약수를 구하고 s.t를 구하는데
오류가 뜨네요..어떻게해야할지 답답해서요
조언부탁합니다.ㅠㅠ
#include stdio.h
void euclid(int a, int b);
void swap(int* a, int*b);
int main()
{
int a, b;
printf(두 정수를 입력하시오 : );
scanf(%d %d, &a, &b);
euclid(a, b);
return 0;
}
void euclid(int a, int b)
{
int r=1, q, sa=1, sb=0, sc, ta=0, tb=1, tc;
// sa=s(i-2), sb=s(i-1), sc=s(i)
// ta=t(i-2), tb=t(i-1), tc=t(i)
int tempa-a, tempb-b;
if(ab)
swap(&a, &b);
while(1) {
q = tempa/tempb;
r = tempa%tempb;
tempa = tempb;
tempb = r;
if(r==0) break;
///////////////////
sc = sa-(q*sb);
sa = sb; sb = sc; // 다음항을 위한 값 변환
tc = ta-(q*tb);
ta = tb; tb = tc;
}
printf( gcd(%d, %d) = %d\n, a, b, tempa);
printf( %d * (%d) + %d = (%d) = %d\n, a, sc, b, tc, tempa);
}
void swap(int* a, int*b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}
-
마중물 2024-03-26
유클리드 호제법을 말씀하시는건가요?
제가 아는 코드랑은 많이 복잡하고 다르네요