我自己写了一个函数GCD计算最大公约数,在lcm最小公倍数函数之中调用GCD,报错了,求指正
#include<bits/stdc++.h>
using namespace std;
long long n,m;
int lcm(int a,int b){
return a*b/GCD(a,b);
}
int GCD(int x,int y){
if(y == 0){
return x;
}else{
return GCD(x,x%y);
}
}
int main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
cin>>n>>m;
n = max(n,m);
m = min(n,m);
cout<<GCD(n,m)<<endl<<lcm(n,m);
return 0;
}
报错信息:
[Error] "GCD" was not declared in this scope