...分别求两个整数的最大公约数和最小公倍数,用主函数调用两个函数并...
发布网友
发布时间:2023-12-25 21:19
我来回答
共1个回答
热心网友
时间:2024-07-22 12:05
include "stdio.h"
int gongyue(int a,int b);
int gongbei(int a,int b);
void main()
{
int a,b,temp,gy,gb;
clrscr();
printf("input two numbers please:");
scanf("%d,%d",&a,&b);
gy = gongyue(a,b);
gb = gongbei(a,b);
printf("最大公约数:%d\n",gy);
printf("最小公倍数:%d\n",gb);
getch();
}
int gongyue(int a,int b)
{
int temp;
while(b!=0)
{
temp=a%b;
a=b;
b=temp;
}
return a;
}
int gongbei(int a,int b)
{
int num,num1,temp;
num=a;
num1=b;
if(num >= num1)
{
temp=num;
num=num1;
num1=temp;
}
temp = gongyue(a,b);
return (num*num1/temp);
}
不明白的发消息给我