學習了一個浮點數取模函數
頭文件:#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;}
新聞熱點
疑難解答