div - C stdlib.h

C examples for stdlib.h:div

Type

function

From


<cstdlib>
<stdlib.h>

Description

Returns the integral quotient and remainder of numer/denom as a structure of type div_t, ldiv_t or lldiv_t, which has two members:quot and rem.

Prototype

lldiv_t div (long long int numer, long long int denom);
  div_t div (int numer, int denom);
 ldiv_t div (long int numer, long int denom);

Parameters

Parameter Description
numer Numerator.
denom Denominator.

Return Value

a structure of type div_t, ldiv_t or lldiv_t, which has two members:quot and rem.

int quot;   // quotient
int rem;    // remainder

Demo Code


#include <stdio.h>
#include <stdlib.h>

int main ()//from  ww  w  .ja  v a 2 s  .  co m
{
  div_t divresult;
  divresult = div (8,5);
  printf ("8 div 5 => %d, remainder %d.\n", divresult.quot, divresult.rem);
  return 0;
}

Related Tutorials