64,282
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
using namespace std;
int main(){
int f1(int, int);
int f2(int, int, int);
int a, b, x, k;
cout << "请输入两个数" << endl;
cin >> a >> b;
x = f1(a, b);
cout << "最大公约数" << x << endl;
k = f2(a, b, x);
cout << "最小公倍数" << k << endl;
return 0;
}
int f1(int a, int b){
int t, r;
if (b>a)
{
t = a; a = b; b = t;
}
while ((r = a%b) != 0)
{
a = b; b = r;
}
return(b);
}
int f2(int a, int b, int x){
return((a*b) / x);
}