C++ floor() 函數
fmod() 函數是 cmath 頭文件的庫函數,用於求除法的餘數,它接受兩個數字(分子和分母)並返回分子/分母的浮點餘數,該餘數向零四舍五入。
fmod() 函數的語法:
fmod(n, m);
參數: n,m
– 是用於計算除法餘數的數字(分子、分母)。
返回值: double
– 它返回 double 類型的值,該值是除法的浮點餘數。
例:
Input:
float n = 5.3;
float m = 2;
Function call:
fmod(n,m);
Output:
1.3
C++代碼演示fmod()函數的例子
// C++ code to demonstrate the example of
// fmod() function
#include <iostream>
#include <cmath>
using namespace std;
// main() section
int main()
{
float n;
float m;
float result;
//input the value of
//numerator and denominator
cout<<"Enter the value of numerator :";
cin>>n;
cout<<"Enter the value of denominator:";
cin>>m;
//finding the remainder
result = fmod(n,m);
cout<<"floating-point remainder of "<<n<<"/"<<m<<" is:";
cout<<result<<endl;
return 0;
}
輸出
Enter the value of numerator:5.3 Enter the value of denominator:2 floating-point remainder of 5.3/2 is:1.3 Second run: Enter the value of numerator:18.5 Enter the value of denominator:4.2 floating-point remainder of 18.5/4.2 is:1.7 Third run: Enter the value of numerator:-36.23 Enter the value of denominator:24.1 floating-point remainder of -36.23/24.1 is:-12.13 Fourth run: Enter the value of numerator:36.23 Enter the value of denominator:-24.1 floating-point remainder of 36.23/-24.1 is:12.13
相關用法
- C++ fmax()用法及代碼示例
- C++ fmin()用法及代碼示例
- C++ fmax() and fmin()用法及代碼示例
- C++ fma()用法及代碼示例
- C++ fdim()用法及代碼示例
- C++ forward_list::unique()用法及代碼示例
- C++ forward_list::emplace_front()用法及代碼示例
- C++ forward_list::reverse()用法及代碼示例
- C++ forward_list::swap()用法及代碼示例
- C++ forward_list::front()、forward_list::empty()用法及代碼示例
- C++ functional::bad_function_call用法及代碼示例
- C++ find_if()用法及代碼示例
- C++ find()用法及代碼示例
- C++ forward_list::operator=用法及代碼示例
- C++ forward_list::clear()、forward_list::erase_after()用法及代碼示例
- C++ forward_list emplace_after()、emplace_front()用法及代碼示例
- C++ forward_list::splice_after()用法及代碼示例
- C++ free()用法及代碼示例
- C++ forward_list resize()用法及代碼示例
- C++ forward_list merge()用法及代碼示例
注:本文由純淨天空篩選整理自 fmod() function with example in C++。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。