/*输入两个数字,求其最大公约数和最小公倍数*/
#include<stdio.h>
void func1(int b, int c);
void func2(int b, int c);
void func1(int b, int c) //求最大公约数
{
int i = 0;
int j = 0;
if (b > c || b == c)
{
for (j = b; j > 0; j--)
{
if (b % j == 0 && c % j == 0)
{
printf("Maximum common multiple is:%d\n", j);
break;
}
else
{
;
}
}
}
else
{
for (j = c; j > 0; j--)
{
if (c % j == 0 && b % j == 0)
{
printf("Maximum common multiple is:%d\n", j);
break;
}
else
{
;
}
}
}
}
void func2(int b, int c)//求最小公倍数
{
int j = 0;
if (b > c || b == c)
{
for (j = b; j < (b * c) + 1; j++) //最小公倍数小于等于两个数的乘积 且大于两数中较大的数
{
if (j % c == 0 && j % b == 0)
{
printf("Least common multiple is:%d\n", j);
printf("___________________________________\n");
break;
}
break;
}
}
else
{
for (j = c; j < (b * c) + 1; j++)
{
if (j % b == 0 && j % c == 0)
{
printf("Least common multiple is:%d\n", j);
printf("___________________________________\n");
break;
}
break;
}
}
}
int main()
{
while (1)
{
int a = 0;
int b = 0;
printf("input First number:");
scanf_s("%d", &a);
printf("input second number:");
scanf_s("%d", &b);
func1(a, b);
func2(a, b);
}
}
题目:输入两个数字,求其最大公约数和最小公倍数
最新推荐文章于 2022-08-29 16:00:59 发布