![]() |
C - Entwicklung Mathematik: Division, Quotient und Rest Homepage von PS-Trainer - C-Entwicklung - Mathematik - an 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 );
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
|
||||||
| 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> void main( int argc, char *argv[]
) x = atoi( argv[1] ); printf( "x is %d, y is
%d\n", x, y ); |
| ldiv Computes the quotient and remainder of a long integer. ldiv_t ldiv( long int numer, long int denom );
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
|
||||||
|
Example #include <stdlib.h> void main( void ) div_result = ldiv( x, y ); |
| fmod Calculates the floating-point remainder. double fmod( double x, double y );
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
|
||||||
| Example /* FMOD.C: This program displays a * floating-point remainder. */ #include <math.h> void main( void ) z = fmod( x, y ); } |
| Aktuelle Daten dieser Seite | Letzte Änderung: |
| |