Compute the integer quotient and remainder.
Compatibility:This function is compatible with the following targets:
|
|
#include <stdlib.h>
div_t div(int numer, int denom);Parameters:
Parameters for this facility are:
The div_t type is defined in stdlib.h as
typedef struct { int quot,rem; } div_t;
div() divides denom into numer and returns the quotient and remainder as a div_t type.
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
div_t result;
ldiv_t lresult;
int d = 10, n = 103;
long int ld = 1000L, ln = 1000005L;
result = div(n, d);
lresult = ldiv(ln, ld);
printf("%d / %d has a quotient of %d\n",
n, d, result.quot);
printf("and a remainder of %d\n", result.rem);
printf("%ld / %ld has a quotient of %ld\n",
ln, ld, lresult.quot);
printf("and a remainder of %ld\n", lresult.rem);
return 0;
}
Output:
103 / 10 has a quotient of 10
and a remainder of 3
1000005 / 1000 has a quotient of 1000
and a remainder of 5
[ First ] [ Previous ] [ Next ] [ Last ] [ Manuals ]
Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.
Last updated: August 16, 2000