linux C(hello world)最大公約數和最小公倍數

weixin_34126215發表於2014-07-23
# include <stdio.h>

int  main(void)
{
	int x, y,temp;
	int r; 
	printf("請輸入兩個正整數:\n");
	scanf("%d %d", &num1, &num2);
	r = num1 % num2;
	temp = num2;
	while(r!=0)
	{
		num1 = num2;
		num2 = r;
		r = num1 % num2;
	}
printf("它們的最大公約數為:%d\n", num2);
	printf("它們的最小公倍數為:%d\n", num1*temp/num2);
	
	return 0;
}

相關文章