//辗转相除
#include<stdio.h>
int main(){
int x, y, z, m, n;
printf("请输入两个数:");
scanf("%d%d", &x, &y);
m = x, n = y;
while (y != 0)
{
z = x%y;
x = y;
y = z;
}
printf("最大公约数是: %d\n", x);
printf("最小公倍数是: %d\n", m*n / x);
return 0;
}
辗转相减
#include<stdio.h> //辗转相减
int main()
{
int x, y, m, n;
printf("请输入两个数:");
scanf("%d%d", &x, &y);
m = x, n = y;
while (x!=y)
{
if (x>y)
x = x-y;
else
y = y-x;
}
printf("最大公约数是: %d\n", x);
printf("最小公倍数是: %d\n", m*n / x);
return 0;
}