PS-Trainer C - Entwicklung
Mathematik: Division, Quotient und Rest
Homepage von PS-Trainer - C-Entwicklung - Mathematik - an PS-Trainer
PS-Trainer PS-Trainer

Math and related Division, Quotient and Reminder:
div Compute the quotient and the remainder of two integer values.
ldiv Compute the quotient and the remainder of a long integer.
fmod Calculate the floating-point remainder.


div
Computes the quotient and the remainder of two integer values.
div_t div( int numer, int denom );

Routine Required Header Compatibility
div  <stdlib.h> ANSI, Win 95, Win NT

Remarks
The div function divides numer by denom, computing the quotient and the remainder. The div_t structure contains int quot, the quotient, and int rem, the remainder. The sign of the quotient is the same as that of the mathematical quotient. Its absolute value is the largest integer that is less than the absolute value of the mathematical quotient. If the denominator is 0, the program terminates with an error message.

Subject: Floating-Point Support Routines
Keywords: See Also ldiv
Return Value
div returns a structure of type div_t, comprising the quotient and the remainder. The structure is defined in STDLIB.H.

Parameters
numer Numerator
denom Denominator
Example
/* DIV.C: This example takes two integers as command-line
* arguments and displays the results of the integer
* division. This program accepts two arguments on the
* command line following the program name, then calls
* div to divide the first argument by the second.
* Finally, it prints the structure members quot and rem.
*/

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

void main( int argc, char *argv[] )
{
int x,y;
div_t div_result;

x = atoi( argv[1] );
y = atoi( argv[2] );

printf( "x is %d, y is %d\n", x, y );
div_result = div( x, y );
printf( "The quotient is %d, and the remainder is %d\n",
div_result.quot, div_result.rem );
}


Output
x is 876, y is 13
The quotient is 67, and the remainder is 5


ldiv
Computes the quotient and remainder of a long integer.
ldiv_t ldiv( long int numer, long int denom );

Routine Required Header Compatibility
ldiv  <stdlib.h> ANSI, Win 95, Win NT

Remarks
The ldiv function divides numer by denom, computing the quotient and remainder.
The sign of the quotient is the same as that of the mathematical quotient.
The absolute value of the quotient is the largest integer that is less than the absolute value of the mathematical quotient.
If the denominator is 0, the program terminates with an error message.
ldiv is the same as div, except that the arguments of ldiv and the members of the returned structure are all of type long int.
The ldiv_t structure, defined in STDLIB.H, contains long int quot, the quotient, and long int rem, the remainder.

Subject: Floating-Point Support Routines
Keywords: See Also div
Return Value
ldiv returns a structure of type ldiv_t that comprises both the quotient and the remainder.

Parameters

numer Numerator
denom Denominator

Example
/* LDIV.C: This program takes two long integers
* as command-line arguments and displays the
* results of the integer division.
*/

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

void main( void )
{
long x = 5149627, y = 234879;
ldiv_t div_result;

div_result = ldiv( x, y );
printf( "For %ld / %ld, the quotient is ", x, y );
printf( "%ld, and the remainder is %ld\n",
div_result.quot, div_result.rem );
}


Output
For 5149627 / 234879, the quotient is 21, and the remainder is 217168


fmod
Calculates the floating-point remainder.
double fmod( double x, double y );

Function Required Header Compatibility
fmod  <math.h> ANSI, Win 95, Win NT

Remarks
The fmod function calculates the floating-point remainder f of x/y such that x = i * y + f, where i is an integer, f has the same sign as x, and the absolute value of f is less than the absolute value of y.

Subject: Floating-Point Support Routines
Keywords: See Also ceil, fabs, floor
Return Value
fmod returns the floating-point remainder of x/y. If the value of y is 0.0, fmod returns a quiet NaN. For information about representation of a quiet NaN by the printf family, see printf.

Parameters
x Floating-point value
y Floating-point value
Example
/* FMOD.C: This program displays a
* floating-point remainder.
*/

#include <math.h>
#include <stdio.h>

void main( void )
{
double w = -10.0, x = 3.0, y = 0.0, z;

z = fmod( x, y );
printf( "The remainder of %.2f / %.2f is %f\n", w, x, z );
printf( "The remainder of %.2f / %.2f is %f\n", x, y, z );

}

Output
The remainder of -10.00 / 3.00 is -1.000000


Homepage von PS-Trainer - C-Entwicklung - Mathematik - an PS-Trainer

Aktuelle Daten dieser Seite Letzte Änderung:
  Geocities

 

 

 

Hosted by www.Geocities.ws

1