#include<stdio.h>
int LMC(int a,int b);
int main ()
{
int x,y;
printf("Inputx,y:");
scanf("%d%d",&x,&y);
printf("%d\n",LMC(x,y));
return 0;
}
int LMC(int a,int b)
{
int x;
int find=0;
for(x=1;!find;x++)
{
if(x%a==0&&x%b==0)
{
find=1;
}
}
return x-1;
}
运行结果:
知识点:
1.学会使用穷举法编程计算两个整数的最小公倍数;
2.for循环语句后面没有“;”。
心得体会:
1.不能认为调用一个函数总会成功,要考虑到如果调用失败该如何处理;
2.学会使用函数最小公倍数函数。