在哪里做到了t*n*m ????
#include <stdio.h>
/************found************/
fun(int x,int y,int z )
{ int j,t ,n ,m;
j = 1 ;
t=j%x;
m=j%y;
n=j%z;
while(t!=0||m!=0||n!=0)
{ j = j+1;
t=j%x;
m=j%y;
n=j%z;
}
/************found************/
return j;
}
main( )
{ int x1,x2,x3,j ;
printf("Input x1 x2 x3: ");
scanf("%d%d%d",&x1,&x2,&x3);
printf("x1=%d, x2=%d, x3=%d \n",x1,x2,x3);
j=fun(x1,x2,x3);
printf("The minimal common multiple is : %d\n",j);
}
回复 .:
#include <stdio.h>
/************found************/
fun(int x, y, z ) //15 11 2
{ int j,t ,n ,m;
j = 1 ;
t=j%x; //t=1
m=j%y ; //m=1
n=j%z; //n=1
while(t!=0||m!=0||n!=0)
{ j = j+1; //这里是在将j一直叠加,然后一直除以xyz,当这个j除以xyz的余数都为零的时候才会跳出循环,所以这样得到的j就是这三个数的最小公倍数咯
t=j%x;
m=j%y;
n=j%z;
}
/************found************/
return i;
}