判断两个双精度浮点数是否整除!
时间: 2023-08-27 14:05:45 浏览: 317
关于浮点数的精度问题
判断两个双精度浮点数是否整除可以将它们相除并取余数,如果余数为0则说明它们整除。代码示例:
```C++
#include <iostream>
#include <cmath>
using namespace std;
bool isDivisible(double a, double b) {
double quotient = a / b;
double remainder = fmod(a, b);
if (remainder == 0) {
return true;
} else {
return false;
}
}
int main() {
double num1 = 12.0;
double num2 = 3.0;
if (isDivisible(num1, num2)) {
cout << num1 << " is divisible by " << num2 << endl;
} else {
cout << num1 << " is not divisible by " << num2 << endl;
}
return 0;
}
```
阅读全文