Uses I/O manipulators to display the table of squares and square roots.
#include <iostream> #include <iomanip> #include <cmath> using namespace std; int main() { double x; cout << setprecision(4); cout << " x sqrt(x) x^2\n\n"; for(x = 2.0; x <= 20.0; x++) { cout << setw(7) << x << " "; cout << setw(7) << sqrt(x) << " "; cout << setw(7) << x*x << '\n'; } return 0; }
1. | Cout: precision 4 | ||
2. | Demonstrate an I/O manipulator: setprecision(2) and setw(20) | ||
3. | Enters a character and outputs its octal, decimal, and hexadecimal code. |