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

题目:输入两个正整数m和n,求其最大公约数和最小公倍数(C)

#include 
#include 
#include 

int main()
{	
	int m,n,i,rem1,rem2;
	int com_div=1,com_mul=1;
	scanf("%d,%d",&m,&n);
	rem1 = m;rem2 = n;
	if (m<=0||n<=0) printf("erro input!");
	i = 1;
	while(i<=m&&i<=n)
	{
		if (rem1%i==0&&rem2%i==0) 
		{	
			com_div = com_div*i;
			rem1 = rem1/i;
			rem2 = rem2/i;
			i = 1; 
		}
		i++;
	}
	com_mul = com_div*rem1*rem2;
	printf("max common div: %d\n",com_div);
	printf("min common mul: %d\n",com_mul);
	
	
	return 0;
	}

你可能感兴趣的:(C)