#include<stdio.h>
int cacu(int a,int b){
int temp;
temp=a%b;
while(temp!=0){
a=b;
b=temp;
temp=a%b;
}
return b;
}
int Minbei(int a,int b){
int temp;
temp=cacu(a,b);
return (a*b/temp);
}
void main()
{ int a,b,c,d;
scanf("%d,%d",&a,&b);
c=cacu(a,b);
d=Minbei(a,b);
printf("%d,\n",c);
printf("%d",d);
}
这个程序是求两个数的最大公约数和最小公倍数
我输入12和8后输出结果是
-4
429496732
为什么会这样我的程序没错啊编译也通过了啊
希望帮帮忙
格式输入时,你的是逗号,输入时可能用空格隔开两个数了
#include<stdio.h>
int Gcd(int a,int b){
int temp;
do{
temp=a%b;
a=b;
b=temp;
}while(temp!=0);
return a;
}
int Lcm(int a,int b){
int temp;
temp=Gcd(a,b);
return (a*b/temp);
}
int main()
{
int a,b,c,d;
scanf("%d %d",&a,&b);
c=Gcd(a,b);
d=Lcm(a,b);
printf("%d\n",c);
printf("%d\n",d);
return 0;
}