您的位置:首页 > 其它

求两个整数的最大公约数和最小公倍数

2015-01-02 16:53 204 查看
#include <stdio.h>

int main()
{
int a, b, n1, n2, temp;
printf("input first number:\t");
scanf("%d", &n1);
printf("input second number:\t");
scanf("%d", &n2);

if (n1 < n2)
{
temp = n1;
n1 = n2;
n2 = temp;
}

a = n1;
b = n2;

while (b != 0)
{
temp = a%b;
a = b;
b = temp;
}

printf("最大公约数为:%d\n", a);
printf("最小公倍数为:%d\n", n1*n2/a);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐