fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. void format(double d)
  6. {
  7. cout << setw(7) << fixed << setprecision(3) << d << endl;
  8. //printf("%7.3f\n", d);
  9. }
  10.  
  11. int main() {
  12. // your code goes here
  13. format(3.45678);
  14. format(123.4);
  15. format(123.45678);
  16. format(0);
  17. format(1000);
  18. return 0;
  19. }
Success #stdin #stdout 0s 16048KB
stdin
Standard input is empty
stdout
  3.457
123.400
123.457
  0.000
1000.000