求两个正整数的最大公约数和最小公倍数(法一)

时间:2022-06-24 00:36:11
#include <stdio.h>
void main()
{
 int a,b,r,sa,sb;
 printf("Input two integer numbers:\n");
 scanf("%d%d",&a,&b);
 sa=a;sb=b;
 if(a<b)
 {
  r=a;
  a=b;
  b=r;
 }
 r=a%b;
 while(r!=0)
 {
  a=b;
  b=r;
  r=a%b;
 }
 printf("The grtest commn divisor:%d\n",b);
 printf("The lowest common multiple:%d\n",sa*sb/b);
 getch()
}