当前位置: C语言 -- 标准库 -- <inttypes.h> -- imaxdiv

imaxdiv函数


概要:
#include <inttypes.h>
imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom);

描述:

该函数通过一次运算计算出(numer/denom)和(numer%denom)的值。


参数:
intmax_t numer

参数为一个intmax_t类型的整数。

intmax_t denom

参数为一个intmax_t类型的整数。


返回值:

函数返回一个imaxdiv_t类型的结构,该结构包含两个成员:商(quot)和余数(rem),成员类型均为imaxdiv_t类型,成员在结构中的顺序ISO/IEC 9899:2018标准未作规定。如果结果的任何部分不能正常表示,函数行为是未定义的。


范例:
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
/*函数imaxdiv范例*/

#include <inttypes.h>
#include <stdio.h>

int main(void)
{
    imaxdiv_t divResult;

    divResult = imaxdiv(10,3);
    printf("The quotient is %jd and the remainder is %jd.\n",
           divResult.quot, divResult.rem);

    return 0;
}

输出:

The quotient is 3 and the remainder is 1.


相关内容:
imaxdiv_t 表示imaxdiv函数返回值的类型。