回覆列表
-
1 # 現在答題全靠運氣的
-
2 # 大臉貓662
#include<stdio.h>
void main()
{
int a,b,n,m;
printf(“please input a and b:\n”);
scanf(“%d%d”,&a,&b);
if(a<1||b<1)
{
printf(“input isn"t correct.\n”);
return;
}
m=a×b;
while(b!=0)
{
t=a%b;
a=b;
b=n;
}
printf(“最大公約數是%d,最小公倍數是%d\n”);
}
#include<stdio.h>
int main(void)
{
int m,n;
int t;
int r;
int product;
printf("請輸入2個正整數(空格分隔):");
scanf("%d %d",&m,&n);
if(m < n) { //當 m 較小時,將 m 和 n 互換
t = m;
m = n;
n = t;
}
product = m * n;
while(1) {
r = m % n;
if(r == 0) {
printf("最大公約數是:%d\n最小公倍數是:%d\n",n,product/n);
break;
}
else {
m = n;
n = r;
}
}
return 0;
}