c 语言哈,写两个函数,分别求两个整数的最大公约数和 最小公倍数,用主函数调用这两个函数,并输出结果。

来源:百度知道 编辑:UC知道 时间:2024/07/02 05:44:42

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);
}

不明白的发消息给我

http://zhidao.baidu.com/question/18339297.html