Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C library function - div()

C library function - div()

C Standard Library - <stdlib.h> C Standard Library -

Description

C Library Function div_t div(int numer, int denom) Divides the **numer (numerator)** by denom (denominator).

Declaration

The following is the declaration of the div() function.



div_t div(int numer, int denom)

Parameters

Return Value

This function returns the value in a structure defined in with two members, such as div_t:int quot; int rem;.

Example

The following example demonstrates the use of the div() function.



#include 

#include 



int main()

{

   div_t output;



   output = div(27, 4);

   printf("(27/ 4) 的商  = %d\n", output.quot);

   printf("(27/4) 的余数 = %d\n", output.rem);



   output = div(27, 3);

   printf("(27/ 3) 的商 = %d\n", output.quot);

   printf("(27/3) 的余数 = %d\n", output.rem);



   return(0);

}

Let's compile and run the above program, which will produce the following result:



(27/ 4) 的商 = 6

(27/4) 的余数 = 3

(27/ 3) 的商 = 9

(27/3) 的余数 = 0

C Standard Library - <stdlib.h> C Standard Library -