开发者社区 问答 正文

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

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

展开
收起
a123456678 2016-03-23 16:17:31 3056 分享 版权
1 条回答
写回答
取消 提交回答
  •  #include "stdio.h"
    #include "conio.h"
    main()
    {
      int a,b,num1,num2,temp;
      printf("please input two numbers:\n");
      scanf("%d,%d",&num1,&num2);
      if(num1<num2)
      {
        temp=num1;
        num1=num2;
        num2=temp;
      }
      a=num1;b=num2;
      while(b!=0)/*利用辗除法,直到b为0为止*/
      {
        temp=a%b;
        a=b;
        b=temp;
      }
      printf("gongyueshu:%d\n",a);
      printf("gongbeishu:%d\n",num1*num2/a);
      getch();
    }
    2019-07-17 19:11:27
    赞同 展开评论
问答地址: