fmod() 浮点数取模

头文件:#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;

}

 

原文链接:

https://blog.csdn.net/innounce/article/details/55279818

posted @ 2020-06-01 10:07  HunterK  阅读(630)  评论(0)    收藏  举报