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:
According to Tutorialspoint
Previous lesson: Function abs () in C
Next lesson: Labs () function in C
4 ★ | 2 Vote
You should read it
May be interested
- Labs () function in Cfunction long int labs (long int x) returns the absolute value of x.
- The function ldiv () in Cthe div_t div function (long int numer, long int denom) divides the numerator numer to denom.
- The function rand () in Cthe function int rand (void) returns a random number in the range from 0 to rand_max.
- The function srand () in Cthe function void srand (unsigned int seed) provides seed for the random number generator used by the rand function.
- The function mblen () in Cthe function int mblen (const char * str, n) returns the length of a multi-byte char pointed to by parameter str.
- The function mbstowcs () in Cfunction 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.