[C언어] 최대공약수, 최소공배수 구하기


최대공약수 : Greatest Common Divisor

최소공배수 : Least Common Multiple


#include<stdio.h>

int main(void){

int GCD, LCM, a, b, num1, num2, r;

printf("enter two numbers\n");

scanf("%d %d", &num1, &num2);

a=num1;

b=num2;

while(b!=0){

r=a&b;

a=b;

b=r;

}

GCD=a;

LCM=(num1*num2)/GCD;

printf("greatest common divisor of %d and %d = %d", num1, num2, GCD);

printf("least common multiple of %d and %d = %d", num1, num2, LCM);

getch();

return 0;

}

+ Recent posts