RAD Studio |  |

div

Header File

stdlib.h

Category

Math Routines

Prototype

div_t div(int numer, int denom);

Description

Divides two integers, returning quotient and remainder.

div divides two integers and returns both the quotient and the remainder as a div_t type. numer and denom are the numerator and denominator, respectively. The div_t type is a structure of integers defined (with typedef) in stdlib.h as follows:

typedef struct {

int quot; /* quotient */

int rem; /* remainder */

} div_t;

Return Value

div returns a structure whose elements are quot (the quotient) and rem (the remainder).

Example

Copy Code

    /* div example */
    #include <stdlib.h>
    #include <stdio.h>
    div_t x;
    int main(void)
    {
       x = div(10,3);
       printf("10 div 3 = %d remainder %d\n",
       x.quot, x.rem);
       return 0;
    }

Portability

POSIX | Win32 | ANSI C | ANSI C++
+ | + | + | +

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!