首页 > 其他 > 详细

c——最大公约数和最小公倍数

时间:2019-04-05 16:49:52      阅读:132      评论:0      收藏:0      [点我收藏+]

PTA

 1 #include<stdio.h>
 2 
 3 int main(){
 4 int num1,num2,temp1,temp2,r;
 5 scanf("%d %d",&num1,&num2);
 6 temp1 = num1;
 7 temp2 = num2;
 8 while(temp2 != 0){
 9     r = temp1 % temp2;
10     temp1 = temp2;
11     temp2 = r;
12 }
13 printf("%d %d\n",temp1,num1*num2/temp1);
14 }

求最大公约数:辗转相除法

求最小公倍数:两数相乘除以最大公约数

 

c——最大公约数和最小公倍数

原文:https://www.cnblogs.com/cxc1357/p/10659034.html

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