iomanip.cpp 737 B

12345678910111213141516171819202122232425262728
  1. // iomanip.cpp -- using manipulators from iomanip
  2. // some systems require explicitly linking the math library
  3. #include <iostream>
  4. #include <iomanip>
  5. #include <cmath>
  6. int main()
  7. {
  8. using namespace std;
  9. // use new standard manipulators
  10. cout << fixed << right;
  11. // use iomanip manipulators
  12. cout << setw(6) << "N" << setw(14) << "square root"
  13. << setw(15) << "fourth root\n";
  14. double root;
  15. for (int n = 10; n <=100; n += 10)
  16. {
  17. root = sqrt(double(n));
  18. cout << setw(6) << setfill('.') << n << setfill(' ')
  19. << setw(12) << setprecision(3) << root
  20. << setw(14) << setprecision(4) << sqrt(root)
  21. << endl;
  22. }
  23. // std::cin.get();
  24. return 0;
  25. }