|
这个是用辗除法写的:
/*
Name:
Copyright:
Author:
Date: 24-10-07 09:44
Description:
*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b,num1,num2,temp;
printf("please input two numbers:\n");
scanf("%d %d",&num1,&num2);
if(num1)//把两个数互换
{
temp=num1;
num1=num2;
num2=temp;
}
a=num1;//让a、b分别保存num1、num2的副本
b=num2;
while(b!=0)/*利用辗除法,直到b(余数)为0为止*/
{
temp=a%b;//取a和b的余数
a=b;//把b赋给a
b=temp;//把它们的余数赋给b
}
printf("gongyueshu:%d\n",a);
printf("gongbeishu:%d\n",num1*num2/a);
system("pause");
return 0;
} |
|