首页 > 编程语言 > 详细

C语言程序设计教程(第三版)课后习题6.1

时间:2017-11-13 19:01:04      阅读:266      评论:0      收藏:0      [点我收藏+]

题目描述

输入两个正整数m和n,求其最大公约数和最小公倍数。

输入

两个整数

输出

最大公约数,最小公倍数

样例输入

5 7

样例输出

1 35



 1     #include <stdio.h>
 2 
 3     int max_common_diviser(int n1, int n2)
 4     {
 5         int temp;
 6 
 7         if(n1 < n2)
 8         {
 9             temp = n1; n1 = n2; n2 = temp;
10         }
11 
12 
13         while(n1 % n2 != 0)
14         {
15             int t = n2;
16             n2 = n1 % n2;
17             n1 = t;
18         }
19 
20         return n2;
21     }
22 
23     int min_common_multiple(int n1, int n2)
24     {
25         return n1 * n2 / max_common_diviser(n1, n2);
26     }
27 
28     int main(int argc, char const *argv[])
29     {
30 
31         int m, n;
32         while(scanf("%d%d", &m, &n) != EOF)
33         {
34             printf("%d %d\n", max_common_diviser(m, n), min_common_multiple(m, n));
35         }
36 
37         return 0;
38     }

 

C语言程序设计教程(第三版)课后习题6.1

原文:http://www.cnblogs.com/hello-lijj/p/7827601.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!