从键盘输入两个正整数,求这两个正整数的最小公倍数和最大公约数,并输出。

时间:2023-01-01 19:02:39
#include<stdio.h>
#include<math.h>
int main()
{   
    int a,b,aa,bb,t=0,i,gongyue,gongbei;
	scanf("%d%d",&a,&b);
	if(a>=b)
    {   t=a%b;aa=a;	bb=b;
	    if(!t)gongbei=a;
		while(t)
		{aa++;t=(aa%a)||(aa%b);}gongbei=aa;	
       t=a%b;aa=a;bb=b;
	   if(!t)gongyue=b;
	   while(t)
	   { bb--;t=(a%bb)||(b%bb);}gongyue=bb;
	}
	else
	{   i=a;a=b;b=i;
	
	    t=a%b;aa=a;	bb=b;
		if(!t)gongbei=a; 
		while(t)
		{	aa++;t=(aa%a)||(aa%b);	}gongbei=aa;
		
		t=a%b;aa=a;	bb=b;
	   if(!t)gongyue=b;
	   while(t)
	   { bb--; t=(a%bb)||(b%bb); }  gongyue=bb;
		  
	}
    printf("%d %d",gongbei,gongyue);

	return 0;
}