题解分享
题解分享简介
计算浮点数相除的余 - 题解
```
/*#include <bits/stdc++.h>
using namespace std;
int main()
{
//r = a - k * b
double a,b;
double r;
cin >> a >> b;
r = (int)(a*100000) % (int)(b*100000);
cout << r / 100000;
return 0;
}
#include <iostream>
#include <cmath> // 包含对fmod函数的声明
using namespace std;
int main() {
double a, b;
// 输入两个双精度浮点数a和b
cin >> a >> b;
// 计算余数
double remainder = fmod(a, b);
// 输出余数
cout.precision(4); // 设置输出精度为4位小数
cout << fixed << remainder << endl;
return 0;
}
*/
#include <bits/stdc++.h>
using namespace std;
int main()
{
//r = a - k * b
double a,b;
double r;
cin >> a >> b;
r = fmod(a,b); //fmod函数取余数
cout << r;
return 0;
}
```
查看全文
0
0
0
3



