Write a program that tests whether the examples of the math library function calls shown in Fig. 5.2 actually produce the indicated results.

What will be an ideal response?


See the following program:
```
// Testing the math library functions.
#include
#include
#include
using namespace std;

int main()
{
cout << fixed << setprecision( 1 );

cout << "sqrt(" << 900.0 << ") = " << sqrt( 900.0 )
<< "\nsqrt(" << 9.0 << ") = " << sqrt( 9.0 );
cout << "\nexp(" << 1.0 << ") = " << setprecision( 6 )
<< exp( 1.0 ) << "\nexp(" << setprecision( 1 ) << 2.0
<< ") = " << setprecision( 6 ) << exp( 2.0 );
cout << "\nlog(" << 2.718282 << ") = " << setprecision( 1 )
<< log( 2.718282 )
<< "\nlog(" << setprecision( 6 ) << 7.389056 << ") = "
<< setprecision( 1 ) << log( 7.389056 );
cout << "\nlog10(" << 1.0 << ") = " << log10( 1.0 )
<< "\nlog10(" << 10.0 << ") = " << log10( 10.0 )
<< "\nlog10(" << 100.0 << ") = " << log10( 100.0 ) ;
cout << "\nfabs(" << 5.1 << ") = " << fabs( 5.1 )
<< "\nfabs(" << 0.0 << ") = " << fabs( 0.0 )
<< "\nfabs(" << -8.76 << ") = " << fabs( -8.76 );
cout << "\nceil(" << 9.2 << ") = " << ceil( 9.2 )
<< "\nceil(" << -9.8 << ") = " << ceil( -9.8 );
cout << "\nfloor(" << 9.2 << ") = " << floor( 9.2 )
<< "\nfloor(" << -9.8 << ") = " << floor( -9.8 );
cout << "\npow(" << 2.0 << ", " << 7.0 << ") = "
<< pow( 2.0, 7.0 ) << "\npow(" << 9.0 << ", "
<< 0.5 << ") = " << pow( 9.0, 0.5 );
cout << setprecision(3) << "\nfmod("
<< 2.6 << ", " << 1.2 << ") = "
<< fmod( 2.6, 1.2 ) << setprecision( 1 );
cout << "\nsin(" << 0.0 << ") = " << sin( 0.0 );
cout << "\ncos(" << 0.0 << ") = " << cos( 0.0 );
cout << "\ntan(" << 0.0 << ") = " << tan( 0.0 ) << endl;
} // end main
```

Computer Science & Information Technology

You might also like to view...

An uninitialized local variable contains:

a. The value last stored in the memory location reserved for that variable. b. No value. c. A value of zero. d. A randomly assigned value.

Computer Science & Information Technology

To add up all the values in a two-dimensional array it would be best to use

A) one for loop B) two separate for loops C) a nested for loop D) no loop E) one sentinel controlled loop

Computer Science & Information Technology

thread that uses processor cycles to continually test a condition before entering its critical section is said to be ________.

a) lockstep synchronized b) deadlocked c) busy waiting d) indefinitely postponed

Computer Science & Information Technology

The CSS property ____ is an example of a shorthand property.

A. font-style B. font C. font-family D. font-shorthand

Computer Science & Information Technology