Skip to content

Latest commit

 

History

History
111 lines (86 loc) · 3.29 KB

File metadata and controls

111 lines (86 loc) · 3.29 KB
titledescriptionms.dateapi_nameapi_locationapi_typetopic_typef1_keywordshelpviewer_keywords
div, ldiv, lldiv
The Microsoft C runtime library div, ldiv, and lldiv functions compute the quotient and the remainder of two integer values.
11/21/2020
div
ldiv
lldiv
msvcrt.dll
msvcr80.dll
msvcr90.dll
msvcr100.dll
msvcr100_clr0400.dll
msvcr110.dll
msvcr110_clr0400.dll
msvcr120.dll
msvcr120_clr0400.dll
ucrtbase.dll
api-ms-win-crt-utility-l1-1-0.dll
DLLExport
apiref
div
ldiv
lldiv
div function
quotients, computing
quotients
dividing integers
remainder computing

div, ldiv, lldiv

Computes the quotient and the remainder of two integer values.

Syntax

div_tdiv( intnumer, intdenom ); ldiv_tldiv( longnumer, longdenom ); lldiv_tlldiv( long longnumer, long longdenom );
ldiv_tdiv( long numer, long denom ); /* C++ only */lldiv_tdiv( longlong numer, longlong denom ); /* C++ only */

Parameters

numer
The numerator.

denom
The denominator.

Return value

div called by using arguments of type int returns a structure of type div_t, which contains the quotient and the remainder. The return value with arguments of type long is ldiv_t, and the return value with arguments of type long long is lldiv_t. The div_t, ldiv_t, and lldiv_t types are defined in <stdlib.h>.

Remarks

The div function divides numer by denom and computes the quotient and the remainder. The div_t structure contains the quotient, quot, and the remainder, rem. The sign of the quotient is the same as the sign of the mathematical quotient. Its absolute value is the largest integer that's less than the absolute value of the mathematical quotient. If the denominator is 0, the program terminates with an error message.

The overloads of div that take arguments of type long or long long are only available to C++ code. The return types ldiv_t and lldiv_t contains members quot and rem, which have the same meanings as the members of div_t.

Requirements

RoutineRequired header
div, ldiv, lldiv<stdlib.h>

For more compatibility information, see Compatibility.

Example

// crt_div.c// arguments: 876 13// This example takes two integers as command-line// arguments and displays the results of the integer// division. This program accepts two arguments on the// command line following the program name, then calls// div to divide the first argument by the second.// Finally, it prints the structure members quot and rem.//#include<stdlib.h>#include<stdio.h>#include<math.h>intmain( intargc, char*argv[] ) { intx,y; div_tdiv_result; x=atoi( argv[1] ); y=atoi( argv[2] ); printf( "x is %d, y is %d\n", x, y ); div_result=div( x, y ); printf( "The quotient is %d, and the remainder is %d\n", div_result.quot, div_result.rem ); }
x is 876, y is 13 The quotient is 67, and the remainder is 5 

See also

Math and floating-point support
imaxdiv

close