intfun(int a,int b){if(a ==0|| b ==0)return0;// 最小公倍数 = a * b / 最大公约数 int mul = a * b;// 辗转相除法求最大公约数int r =0;//a b 的余数if(a < b){//保证 a > b int t = a;
a = b;
b = t;}//辗转相除法(相关原理可看详细数学证明) while(r = a % b){//r == 0 时结束循环
a = b;
b = r;}return mul / b;}
C语言完整可运行代码
#include<stdio.h>intfun(int a,int b);intmain(){int a,b;scanf("%d,%d",&a,&b);int x =fun(a,b);printf("%d",x);return0;}intfun(int a,int b){if(a ==0|| b ==0)return0;// 最小公倍数 = a * b / 最大公约数 int mul = a * b;// 辗转相除法求最大公约数int r =0;//a b 的余数if(a < b){//保证 a > b int t = a;
a = b;
b = t;}//辗转相除法(相关原理可看详细数学证明) while(r = a % b){//r == 0 时结束循环
a = b;
b = r;}return mul / b;}