c语言 函数的参数传递示例_restder()函数,带有C ++中的示例

c语言 函数的参数传递示例

C ++ restder()函数 (C++ remainder() function)

remainder() function is a library function of cmath header, it is used to calculate the remainder (IEC 60559), it accepts two parameters (numerator and denominator) and returns the remainder (floating-point) of numerator/denominator rounded to nearest,

restder()函数cmath标头的库函数,用于计算余数(IEC 60559),它接受两个参数( 分子分母 ),并返回四舍五入到最接近的分子 / 分母的余数(浮点数),

    remainder = numerator - rquot * denominator

Where, rquot is the value of numerator/denominator (rounded to the nearest integral value with halfway cases rounded toward the even number.

其中, rquot分子 / 分母的值(四舍五入为最接近的整数值,中位数为四舍五入为偶数)。

Syntax of remainder() function:

restder()函数的语法:

C++11:

C ++ 11:

     double remainder (double numer     , double denom);
      float remainder (float numer      , float denom);
long double remainder (long double numer, long double denom);
     double remainder (Type1 numer      , Type2 denom);

Parameter(s):

参数:

  • numer, denom – represent the values of numerator and denominator.

    numer,denom –表示分子分母的值。

Return value:

返回值:

It returns the remainder.

它返回余数。

Note:

注意:

  • If the remainder is 0, then its sign is the same as the sign of numer.

    如果余数为0,则其符号与numer的符号相同。

  • If the value of denom is 0, the result may either 0 or it may cause a domain error.

    如果denom的值为0,则结果可能为0或可能导致域错误。

Example:

例:

    Input:
    double x = 15.46;
    double y = 12.56;
    
    Function call:
    remainder(x, y);
    
    Output:
    2.9

C ++代码来演示restder()函数的示例 (C++ code to demonstrate the example of remainder() function)

// C++ code to demonstrate the example of
// remainder() function

#include <iostream>
#include <cmath>
using namespace std;

// main() section
int main()
{
    double x;
    double y;

    x = 10;
    y = 2;
    cout << "remainder(" << x << "," << y << "): " << remainder(x, y);
    cout << endl;

    x = 5.3;
    y = 2;
    cout << "remainder(" << x << "," << y << "): " << remainder(x, y);
    cout << endl;

    x = 15.46;
    y = 12.56;
    cout << "remainder(" << x << "," << y << "): " << remainder(x, y);
    cout << endl;

    x = -10.2;
    y = 2;
    cout << "remainder(" << x << "," << y << "): " << remainder(x, y);
    cout << endl;

    return 0;
}

Output

输出量

remainder(10,2): 0
remainder(5.3,2): -0.7
remainder(15.46,12.56): 2.9
remainder(-10.2,2): -0.2

Reference: C++ remainder() function

参考: C ++ restder()函数

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

c语言 函数的参数传递示例

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值