[刷题] PTA 7-26 最大公约数和最小公倍数

程序:

 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
",temp1,num1*num2/temp1);
14 }

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

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

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