> 其他 >
写一个求两个数的最大公约数和最小公倍数的函数
人气:225 ℃ 时间:2020-05-11 12:01:18
解答
#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{
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();
}
推荐
猜你喜欢
© 2026 79432.Com All Rights Reserved.
电脑版|手机版