write a function absolute that returns the magnitude of a number.test your function with a program which is terminated by the sentinel 999 as shown in the following input:
enter a real number:-71.32
the absolute value is -71.320
enter a real number:65.1
the absolute value is 65.100
enter a real number:999
the absolute value is 999.000
thank for trying this program!
- ?Lv 61 decade agoFavorite Answer
what do u mean for an "absolute value"?
the absolute value for -71.32 is 71.32.
for the define of absolute value is
In mathematics, the absolute value (or modulus which is Latin for a small measure) of a real number is its numerical value without regard to its sign. So, for example, 3 is the absolute value of both 3 and −3. In computer programming, the mathematical function used to perform this calculation is usually given the name abs().
pls check following code that the absolute value had changed to above algorithms.
void main( )
for ( ; ; )
printf( "Enter a real number : " );
scanf( "%f", &dNum1 );
printf( "The value is %.3f\n", dNum1 );
printf( "The absolute value is %.3f\n\n", fabsf( dNum1 ) );
if ( dNum1 == 999 )
printf( "Thank for trying this program!\n" );
2008-03-28 16:47:45 補充：