首页 > 学院 > 开发设计 > 正文

fmod() 浮点数取模

2019-11-08 18:23:43
字体:
来源:转载
供稿:网友

学习了一个浮点数取模函数

头文件:#include <cmath>fmod() 用来对浮点数进行取模(求余),其原型为: double fmod (double  x,double  y);注意:y不能为0;

例如:4.2对2取模位0.2   4.3对2.1取模位0.1

下面附上C++代码

#include<iostream>#include<cmath>using namespace std;int main(){    double a,b;    while(cin>>a>>b)    cout<<fmod(a,b)<<endl;  //a对b取模    return 0;}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表