Chapter Contents

Previous

Next
lldiv

lldiv



Integer Conversion: Division

Portability: ISO/ANSI C conforming


SYNOPSIS
DESCRIPTION
RETURN VALUE
EXAMPLE
RELATED FUNCTIONS
SEE ALSO


SYNOPSIS

#include <stdlib.h>

lldiv_t lldiv(long long int numer, long long int denom);


DESCRIPTION

lldiv computes the quotient and remainder of numer divided by denom .


RETURN VALUE

div returns a structure of type ldiv_t , which contains both the quotient and remainder. The definition of the ldiv_t type is

typedef struct {
   long long rem;
   long long quot;
}lldiv_t;

The return value is such that

numer == quot * denom + rem

The sign of rem is the same as the sign of numer .


EXAMPLE

This example converts an angle in radians to degrees, minutes, and seconds using lldiv :

#include <math.h>
#include <stdlib.h>
#include <lcmath.h>

main()
{

   double rad, angle;}

   long long deg, min, sec;
   lldiv_t d;

   puts(" Enter any angle in radians: ");
   scanf("%f", &rad);

      /* Convert angles to seconds and discard fraction. */
   angle = rad * (180 * 60 * 60)/M_PI;

   sec = angle;
   d   = lldiv(sec, 60L);
   sec = d.rem;
   d   = lldiv(d.quot, 60L);
   min = d.rem;
   deg = d.quot;

   printf("%f radians = %ld degrees, %ld, %ldn", rad,
           deg, min, sec);
}  


RELATED FUNCTIONS

div


SEE ALSO


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.