作业帮 > 综合 > 作业

用"辗转相除法"对输入的两个正整数M和N求其最大公约数和最小公倍数

来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/10/04 03:34:29
用"辗转相除法"对输入的两个正整数M和N求其最大公约数和最小公倍数
C语言高手来
用
#include int main() { int m, n; int m_temp, n_temp, res; printf("Enter two integer:\n"); scanf("%d %d", &m, &n); m_temp = m; n_temp = n; if (m > 0 && n >0) { do { res = n % m; n = m; m = res; } while (m != 0); printf("Greatest common divisor: %d\n", n); printf("Lease common multiple : %d\n", m_temp * n_temp / n); } else printf("Error!\n"); return 0; }
满意请采纳