c練習題1:求最大公約數,最小公倍數

#include "stdio.h"
int main()
{
int a,b,x,y,temp=1;
printf("請輸入兩個整數:");
scanf("%d%d",&a,&b);
x=a;
y=b;

while (temp!=0)
{
temp=x%y;
x=y;
y=temp;
}
temp=a*b/x;
printf("公約數爲%d\n",x);
printf("最小公倍數爲%d\n",temp);


return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章