c语言fmod函数_fmod()函数以及C ++中的示例

c语言fmod函数

C ++ floor()函数 (C++ floor() function)

fmod() function is a library function of cmath header, it is used to find the remainder of the division, it accepts two numbers (numerator and denominator) and returns the floating-point remainder of numerator/denominator which is rounded towards to zero.

fmod()函数cmath标头的库函数,用于查找除法的余数,它接受两个数字(分子和分母),并返回四舍五入为零的分子/分母的浮点余数。

Syntax of fmod() function:

fmod()函数的语法:

    fmod(n, m);

Parameter(s): n,m – are the numbers (numerator, denominator) to be used to calculate the remainder of the division.

参数: n,m –是用于计算除法余数的数字(分子,分母)。

Return value: double – it returns double type value that is floating-point remainder of the division.

返回值: double-返回double类型的值,该值是除法的浮点余数。

Example:

例:

    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)

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

Output

输出量

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


翻译自: https://www.includehelp.com/cpp-tutorial/fmod-function-with-example.aspx

c语言fmod函数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值