728x90
반응형
지식에서 답변을 달다가 심심해서 하나 올리네요~ ㅎㅎ
#include <stdio.h>
void main()
{
int input1,input2,temp;
int gcd=1,lcm; // gcd : 최대공약수, lcm : 최소공배수
printf("정수 2개를 입력하세요\n");
scanf("%d %d",&input1,&input2);
lcm = input1*input2;
if(input1>input2)
{
temp = input1;
input1 = input2;
input2 = temp;
}
while(gcd!=0)
{
gcd = input1%input2;
input1=input2;
input2=gcd;
}
lcm = lcm/input1;
printf("최대공약수는 %d",input1);
printf("최소공배수는 %d",lcm);
}
728x90
반응형
'C언어' 카테고리의 다른 글
쉘정렬 알고리즘 시간 복잡도 (0) | 2010.10.15 |
---|---|
합병 정렬 알고리즘 (0) | 2010.10.15 |
팩토리얼 재귀함수로 구현하기 (0) | 2009.10.19 |
피보나치 수열 함수로 구현하기 (0) | 2009.10.19 |
하노이탑 함수로 구현하기 (0) | 2009.10.19 |