Notice
Recent Posts
Recent Comments
Creative Code
gcd.c(최대공약수 구하기) 본문
#include <stdio.h>
int gcd(int a, int b) {
while (1){
int Q = a/b;
int R = a%b;
if (R == 0){
return b;
}
a = b;
b = R;
}
}
int main(void)
{
int a,b;
printf("숫자 2개 입력 : ");
scanf("%d %d",&a,&b);
if (b<a) {
int tmp = b;
b = a;
a = tmp;
}
int result = gcd(a,b);
printf("gcd : %d\n",result);
return 0;
}
'C Programming' 카테고리의 다른 글
returnValue.c(함수 인자 포인터로 받기) (0) | 2023.08.03 |
---|---|
swap2.c(함수인자 포인터로 받기) (0) | 2023.08.03 |
power.c(지수 계산하기) (0) | 2023.08.03 |
pointerAndArray2.c(포인터와 배열의 관계) (0) | 2023.08.03 |
arrayCompare.c(두 배열 비교) (0) | 2023.08.03 |