Keil Logo Arm Logo

CARM User's Guide

Discontinued

div

Summary
#include <stdlib.h>

div_t div (
  int num,    /* numerator */
  int den);   /* denominator */
Description

The div function divides numerator by denominator and calculates the mathematical quotient and remainder. If the denominator has a value of zero, the results of the division are undefined.

Return Value

The div function returns a div_t type that contains the quotient and remainder of the division.

See Also

ldiv

Example
#include <stdlib.h>
#include <stdio.h>   /* for printf */

void tst_div(void) {
  div_t res;

  res = div(3456, 2345);              // Do division
  printf ("Division = %d r%d\n", res.quot, res.rem);

  if (res.rem >= 2345/2) res.quot++;  // Round off
  printf ("Round-Off Division = %d\n", res.quot);
}

arm-logo-small

Keil logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.