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;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章