fmod函数用法

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

发布了150 篇原创文章 · 获赞 73 · 访问量 6579

猜你喜欢

转载自blog.csdn.net/queque_heiya/article/details/104259876