#include "stdio.h"
int gcd(int a,int b){
int r;
while(r=a%b)
a=b,b=r;
return b;
}
int lcm(int a,int b){
return a/gcd(a,b)*b;
}
int main(int argc,char *argv[]){
int x,y;
printf("Please enter 2 positive integers...\n");
if(scanf("%d%d",&x,&y)!=2 || x<1 || y<1){
printf("Input error, exit...\n");
return 0;
}
printf("The GCD of %d & %d is %d\n",x,y,gcd(x,y));
printf("The LCM of %d & %d is %d\n",x,y,lcm(x,y));
return 0;
}
运行样例: