Source of library_functions.cpp


  1: //library_functions.cpp
  2: //Illustrates computations involving functions from the C++ cmath library.

  4: #include <iostream>
  5: #include <cmath>
  6: //#include <cstdlib>
  7: using namespace std;

  9: int main()
 10: {
 11:     cout << "\nThis program displays the results of evaluating "
 12:         "expressions\ninvolving functions from the C++ cmath "
 13:         "library.\n\n";

 15:     cout << "The square root of 25.0 is "  << sqrt(25.0)  << ".\n"
 16:          << "The square root of 12.34 is " << sqrt(12.34) << ".\n\n";

 18:     cout << "The absolute value of 2 is "       << abs(2)      << ".\n"
 19:          << "The absolute value of -2 is "      << abs(-2)     << ".\n"
 20:          << "The absolute value of 13.456 is "  << abs(13.456) << ".\n"
 21:          << "The absolute value of -13.456 is " << abs(-13.456)
 22:          << ".\n\n";

 24:     cout << "2.0 raised to the power 3   is " << pow(2.0, 3)   << ".\n"
 25:          << "2.4 raised to the power 3.1 is " << pow(2.4, 3.1) << ".\n"
 26:          << ".04 raised to the power -.5 is " << pow(.04, -.5) << ".\n\n";

 28:     double r;
 29:     r = sqrt(1 + pow(4.0, 3));
 30:     cout << "The square root of 1 more than "
 31:          << "the cube of 4 is " << r << ".\n";
 32:     cout << endl;
 33: }