c语言编程:输入两个正整数m和n,求其最大公约数和最小公倍数.

问题描述:

c语言编程:输入两个正整数m和n,求其最大公约数和最小公倍数.
输入两个正整数m和n,求其最大公约数和最小公倍数.注:最大公约数也称最大公因子,指某几个整数共有因子中最大的一个;两个整数公有的倍数称为它们的公倍数,其中最小的一个正整数称为它们两个的最小公倍数.编程可用素材:printf("please input two integer numbers: ")、printf("\nthe greatest common divisor is …、printf("\nthe least common multiple is ….
  程序的运行效果应类似地如图1所示,图1中的35 15是从键盘输入的内容.
1个回答 分类:综合 2014-11-19

问题解答:

我来补答
#include 
int 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"); 
return 0; 
}
 
 
展开全文阅读
剩余:2000