银河机攻队机体:写两个函数分别求两个整数的最大公约数和最小公倍数用主函数调用这两个函数,并输出结果,两个整数由键盘输

来源:百度文库 编辑:高考问答 时间:2024/04/28 23:47:13
是C语言问题

#include "stdio.h"
#include "conio.h"
main()
{
int a,b,num1,num2,temp;
printf("please input two numbers:\n");
scanf("%d,%d",&num1,&num2);
if(num1<num2)/*交换两个数,使大数放在num1上*/
{
temp=num1;
num1=num2;
num2=temp;
}
a=num1;b=num2;
while(b!=0)/*利用辗除法,直到b为0为止*/
{
temp=a%b;
a=b;
b=temp;
}
printf("gongyueshu:%d\n",a);
printf("gongbeishu:%d\n",num1*num2/a);
getch();
}

#include "stdio.h"
void main()
{int fun(int,int);
void print(int,int);
int x,y;
scanf("%d,%d",&x,&y);
printf("\n");
print(fun(x,y),x*y/fun(x,y));
getch();
}
int fun(int x,int y)
{ int i;
for(i=1;;i++)
if(i*x%y==0) return(i*x);
}
void print(int x,int y)
{printf("%d,%d\n",x,y);}

什么都问,自己做吧~~

很简单的。。。

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

最小公倍数等于两数乘积除以最大公约数