太原电台主持人楚月:作业不会作了.郁闷...

来源:百度文库 编辑:高考问答 时间:2024/05/12 15:50:19
输入正整数X和Y,求其最大公约数和最小公倍数.
用C写. 要怎么写呀??
谢谢.

#include "stdio.h"

main()
{
int a,b,num1,num2,temp;
printf("please input two numbers:\\n");
scanf("%d,%d",&num1,&num2);

a=num1;b=num2;

while(b!=0)/*利用辗除法,直到b为0为止*/
{
temp=a%b;
a=b;
b=temp;
}
printf("gongyueshu:%d\\n",a);
printf("gongbeishu:%d\\n",num1*num2/a);
}