C++ Greatest Common Divisor (GCD) Algorithm: Recursive Implementation
The missing parameter in the recursive call to 'gcd' function should be 'x%y'.
The corrected code is:
#include<iostream>
using namespace std;
int gcd(int x,int y){
if(x%y==0) return y;
else return gcd(y, x%y);
}
int main(){
int x,y;
cin>>x>>y;
cout<<gcd(x,y);
return 0;
}
原文地址: https://www.cveoy.top/t/topic/pSDv 著作权归作者所有。请勿转载和采集!