作业帮 > 综合 > 作业

c++程序,输入两个正数m,n.求最大公约数,和最小公倍数

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/07/17 20:50:31
c++程序,输入两个正数m,n.求最大公约数,和最小公倍数
在vc里面通过调试运行检验功能了
#include
void main()
{
int m,n;
int m_cup,n_cup,res; //被除数,除数,余数
printf("Enter two integer:\n");
scanf("%d %d",&m,&n);
if (m > 0 && n >0)
{
m_cup = m;
n_cup = n;
res = m_cup % n_cup;
while (res != 0)
{
m_cup = n_cup;
n_cup = res;
res = m_cup % n_cup;
}
printf("Greatest common divisor:%d\n",n_cup);
printf("Lease common multiple :%d\n",m * n / n_cup);
}
else
printf("Error!\n");
}