zoukankan      html  css  js  c++  java
  • [刷题] 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 }

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

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

  • 相关阅读:
    十一作业
    11.20
    11.13 第十二次、
    11.13 第十一次、
    11.06第十次、
    11.06第九次、
    10.30
    10.23
    10.16
    10.9
  • 原文地址:https://www.cnblogs.com/cxc1357/p/10659034.html
Copyright © 2011-2022 走看看