Div () function in C

Div () function in C

Div_t div function (int numer, int denom) divides numer numerator for denom .

Declare the div () function in C

Below is the declaration for div () in C:

 div_t div ( int numer , int denom ) 

Parameters

numer : numerator.

denom : denominator.

Returns the value

This function returns the value in an internal, two-part structure, with div_t it is: int quot; int rem;

For example

The following C program illustrates the usage of div () in C:

 #include #include int main () { div_t output ; output = div ( 27 , 4 ); printf ( "Phan thuong cua phep chia (27/ 4) = %dn" , output . quot ); printf ( "Phan du cua phep chia (27/4) = %dn" , output . rem ); output = div ( 27 , 3 ); printf ( "nPhan thuong cua phep chia (27/ 3) = %dn" , output . quot ); printf ( "Phan du cua phep chia (27/3) = %dn" , output . rem ); return ( 0 ); } 

Compiling and running the above C program will result:

Div () function in C Picture 1

According to Tutorialspoint

Previous lesson: Function abs () in C

Next lesson: Labs () function in C

4 ★ | 2 Vote

May be interested

  • Labs () function in CPhoto of Labs () function in C
    function long int labs (long int x) returns the absolute value of x.
  • The function ldiv () in CPhoto of The function ldiv () in C
    the div_t div function (long int numer, long int denom) divides the numerator numer to denom.
  • The function rand () in CPhoto of The function rand () in C
    the function int rand (void) returns a random number in the range from 0 to rand_max.
  • The function srand () in CPhoto of The function srand () in C
    the function void srand (unsigned int seed) provides seed for the random number generator used by the rand function.
  • The function mblen () in CPhoto of The function mblen () in C
    the function int mblen (const char * str, n) returns the length of a multi-byte char pointed to by parameter str.
  • The function mbstowcs () in CPhoto of The function mbstowcs () in C
    function size_t mbstowcs (* pwcs, const char * str, n) converts the sequence of multi-byte char points pointed to by the parameter str to the array pointed to by pwcs.