Name
ldiv - computes quotient and remainder of an integer division
Library
libc.lib
Synopsis
|
ldiv_t
ldiv (long num, long denom);
|
Return values
The
ldiv
function
returns a structure of type
ldiv_t
that contains two
long
members named
quot
(quotient)
and
rem
(remainder).
Detailed description
The
ldiv
function
computes the value
num / denom
and returns the quotient and remainder in a structure named
ldiv_t
that contains two
long
members named
quot
and
rem.
Examples
#include <stdlib.h>
#include <stdio.h>
int main( void )
{
long numer = 13;
long denom = -3;
/* call to ldiv */
ldiv_t x = ldiv(numer, denom);
printf("Result-> \nQuotient = %ld \nRemainder = %ld", x.quot, x.rem);
long exp_numer = (denom * x.quot) + x.rem;
if( exp_numer == (numer) )
printf("\nResult is same as the expected output");
else
printf("\nUnexpected output");
return 0;
}
Output
Result->
Quotient = 4
Remainder = -1
Result is same as the expected output
Errors
No errors are defined.
See also
div,
lldiv
Feedback
For additional information or queries on this page send feedback
© 2005-2007 Nokia
|
|