/* testmath.cpp CIS 150 6/3/2008 David Klick This program demonstrates some basic math library functions. */ #include #include #include using std::cin; using std::cout; using std::setw; using std::fixed; using std::showpoint; using std::setprecision; using std::endl; void cont(); int main() { double x=5.78; double y=6.45; double z=-3.2; // display heading cout << "x --> " << fixed << showpoint << setprecision(2) << setw(8) << x << setw(8) << y << setw(8) << z << '\n'; // display results of functions on values cout << "fabs(x) " << setw(8) << fabs(x) << setw(8) << fabs(y) << setw(8) << fabs(z) << '\n'; cout << "ceil(x) " << setw(8) << ceil(x) << setw(8) << ceil(y) << setw(8) << ceil(z) << '\n'; cout << "floor(x) " << setw(8) << floor(x) << setw(8) << floor(y) << setw(8) << floor(z) << "\n\n\n"; cout << "fmod(7.6, 3.7) = " << fmod(7.6, 3.7) << '\n'; cout << "sqrt(9.0) = " << sqrt(9.0) << '\n'; cout << "pow(4.0, 3.0) = " << pow(4.0, 3.0) << "\n\n"; cont(); return 0; } void cont() { if (cin.rdbuf()->sungetc() != -1 && cin.get() != '\n') cin.ignore(80,'\n'); cout << "Press enter to continue..."; cin.get(); } /* Sample run: x --> 5.78 6.45 -3.20 fabs(x) 5.78 6.45 3.20 ceil(x) 6.00 7.00 -3.00 floor(x) 5.00 6.00 -4.00 fmod(7.6, 3.7) = 0.20 sqrt(9.0) = 3.00 pow(4.0, 3.0) = 64.00 Press enter to continue... */