c语言 div ldiv_C ++中带有示例的ldiv()函数

c语言 div ldiv

C ++ ldiv()函数 (C++ ldiv() function)

ldiv() function is a library function of cstdlib header. It is used for integral division, it accepts two parameters (numerator and denominator) and returns a structure that contains the quot (quotient) and rem (remainder).

ldiv()函数cstdlib标头的库函数。 它用于整数除法,它接受两个参数( 分子分母 ),并返回一个包含quot ( )和rem ( remaind )的结构。

Syntax of ldiv() function:

ldiv()函数的语法:

C++11:

C ++ 11:

    ldiv_t ldiv (long int numer, long int denom);

Parameter(s):

参数:

  • numer – represents the value of numerator.

    numer –代表分子的值。

  • denom – represents the value of denominator.

    denom –代表分母的值。

Return value:

返回值:

The return type of this function is ldiv_t, returns a structure that contains the quot (quotient) and rem (remainder).

该函数的返回类型为ldiv_t ,返回一个包含quot ( quotient )和rem ( 其余部分 )的结构。

Example:

例:

    Input:
    long int n = 123456789;
    long int d = 12345678;
    ldiv_t result;

    Function call:
    result = ldiv(n, d);

    Output:
    result.quot = 10
    result.rem = 9

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

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

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

// main() section
int main()
{

    long int n = 123456789;
    long int d = 12345678;
    ldiv_t result;

    result = ldiv(n, d);

    cout << "Numerator  : " << n << endl;
    cout << "Denominator: " << d << endl;
    cout << "Quotient   : " << result.quot << endl;
    cout << "Remainder  : " << result.rem << endl;
    cout << endl;

    n = 999988887777;
    d = 1112223334;

    result = ldiv(n, d);

    cout << "Numerator  : " << n << endl;
    cout << "Denominator: " << d << endl;
    cout << "Quotient   : " << result.quot << endl;
    cout << "Remainder  : " << result.rem << endl;
    cout << endl;

    n = 100100234;
    d = 9878762536;

    result = ldiv(n, d);

    cout << "Numerator  : " << n << endl;
    cout << "Denominator: " << d << endl;
    cout << "Quotient   : " << result.quot << endl;
    cout << "Remainder  : " << result.rem << endl;
    cout << endl;

    return 0;
}

Output

输出量

Numerator  : 123456789
Denominator: 12345678
Quotient   : 10
Remainder  : 9

Numerator  : 999988887777
Denominator: 1112223334
Quotient   : 899
Remainder  : 100110511

Numerator  : 100100234   
Denominator: 9878762536
Quotient   : 0
Remainder  : 100100234

Reference: C++ ldiv() function

参考: C ++ ldiv()函数

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

c语言 div ldiv

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值