发布网友 发布时间:2022-04-23 08:10
共3个回答
热心网友 时间:2022-06-18 04:35
int MaxAB(int a,int b)
{
if(a>b && !a%b || a==b) return a;
if(a < b && !b%a) return b;
//先求最大公约数
int nMul;
int nMinAB = (a>b)?(nMul=b,a%b):(nMul=a,b%a);
while(nMinAB)
{
int nTemp = nMinAB;
nMinAB = nMul % nMinAB;
nMul = nTemp;
}
return A*B/nMul;
}
热心网友 时间:2022-06-18 04:36
#include <stdio.h>
int *(int a, int b)
{
int r = 0;// remainder
int q; // quotient
int d;
d = (a >= b ? a : b);
if (d == a)
q = b;
else
q = a;
printf("d: %d\t q: %d\n", d, q);
do {
r = d % q ;
if (r == 0)
break;
d = q;
q = r;
} while (r != 0);
printf("d: %d\t q: %d\n", d, q);
return q;
}
int lcm(int a, int b)
{
if (a != 0 && b != 0)
return a * b / *(a, b);
return 0;
}
int main()
{
int a, b;
printf("Please input two number: ");
scanf("%d,%d", &a, &b);
getchar();
printf("The Greatest common divided number: %d\n", *(a, b));
printf("The lowest common multiple number: %d\n", lcm(a, b));
getchar();
return 0;
}
热心网友 时间:2022-06-18 04:36
A*B=最小公倍数追问用算法!