cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : C Library : cstdlib (stdlib.h) : div
 
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
C Library
cassert (assert.h)
cctype (ctype.h)
cerrno (errno.h)
cfloat (float.h)
climits (limits.h)
clocale (locale.h)
cmath (math.h)
csetjmp (setjmp.h)
csignal (signal.h)
cstdarg (stdarg.h)
cstddef (stddef.h)
cstdio (stdio.h)
cstdlib (stdlib.h)
cstring (string.h)
ctime (time.h)
cstdlib (stdlib.h)
functions:
· abort
· abs
· atexit
· atof
· atoi
· atol
· bsearch
· calloc
· div
· exit
· free
· getenv
· labs
· ldiv
· malloc
· mblen
· mbstowcs
· mbtowc
· qsort
· rand
· realloc
· srand
· strtod
· strtol
· strtoul
· system
· wcstombs
· wctomb
functions (non-standard):
· itoa
macros:
· EXIT_FAILURE
· EXIT_SUCCESS
· MB_CUR_MAX
· NULL
· RAND_MAX
types:
· div_t
· ldiv_t
· size_t

-

div function
div_t div ( int numerator, int denominator );
ldiv_t div ( long numerator, long denominator );
<cstdlib>

Integral division

Returns the integral quotient and remainder of the division of numerator by denominator as a structure of type div_t or ldiv_t, which has two members: quot and rem.

Parameters

numerator
Numerator.
denom
Denominator.

Return Value

The result is returned by value in a structure defined in <cstdlib>, which has two members. For div_t, these are, in either order:
int quot;
int rem;

and for ldiv_t:
long quot;
long rem;

Portability

In C, only the int version exists.

Example

/* div example */
#include <stdio.h>
#include <stdlib.h>

int main ()
{
  div_t divresult;
  divresult = div (38,5);
  printf ("38 div 5 => %d, remainder %d.\n", divresult.quot, divresult.rem);
  return 0;
}

Output:


38 div 5 => 7, remainder 3.

See also

ldiv Integral division (function)
© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us