fmod是对浮点数求余数,而一般的%运算不符合语法规则;
如一下代码:
#include<iostream>
#include<cmath>
using namespace std;
int main(){
//cout<<3%2.0<<endl;//出错
cout<<fmod(3,2.1)<<endl;
}
程序运行的结果为:
0.9
--------------------------------
Process exited after 2.557 seconds with return value 0
请按任意键继续. . .
具体参考:https://blog.csdn.net/weixin_30888413/article/details/98555913