用c语言分别设计求两个正整数的最大公约数、最小公倍数的函数。主函数输入任意的两个整数,

分别设计求两个正整数的最大公约数、最小公倍数的函数。主函数输入任意的两个整数,通过函数调用分别输出最大公约数、最小公倍数。

第1个回答  2016-11-13
#include<stdio.h>
void main( )
{
int gongyueshu( int a, int b );
int gongbeishu( int a, int b );
int a, b, c, d;
printf("please input two integer numbers:");
scanf("%d%d", &a, &b);
c=gongyueshu(a, b);
d=gongbeishu(a, b);
printf("gongyueshu is %d\n gongbeishu is %d",c,d);
}
int gongyueshu( int a, int b )
{
int t=a<b?a:b;
while(a%t||b%t)
{
t--;
}
return t;
}
int gongbeishu( int a, int b )
{
int t=a<b?b:a;
while(t%a||t%b)
{
t++;
}
return t;
}本回答被网友采纳
相似回答