在本教程中,我们将讨论查找浮点数的GCD的程序。
为此,我们将提供两个整数。我们的任务是找到这两个提供的整数的GCD(最大公约数)。
#include <bits/stdc++.h>
using namespace std;
//returning GCD of given numbers
double gcd(double a, double b){
if (a < b)
return gcd(b, a);
if (fabs(b) < 0.001)
return a;
else
return (gcd(b, a - floor(a / b) * b));
}
int main(){
double a = 1.20, b = 22.5;
cout << gcd(a, b);
return 0;
}
输出结果
0.3