fork download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6. long double pierwiastek(long double x, long double eps) {
  7.  
  8. long double a = 0.0;
  9. long double b = x;
  10. long double c;
  11. while (fabs(b - a) > eps) {
  12. c = (a + b) / 2;
  13. if (c * c > x)
  14. b = c;
  15. else
  16. a = c;
  17. }
  18. return c;
  19. }
  20. int main () {
  21. long double x = 2;
  22. cout << setprecision(2) << sqrt(2) << endl;
  23. cout << setprecision(3) << sqrt(2) << endl;
  24. cout << setprecision(5) << sqrt(2) << endl;
  25. return 0;
  26. }
Success #stdin #stdout 0.01s 5256KB
stdin
1
2
10
42
11
stdout
1.4
1.41
1.4142