fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main(int argc, char** argv)
  6. {
  7. printf("using printf\n");
  8. printf("% .5e\n", M_PI);
  9. printf("% .5e\n", -M_PI);
  10. printf("decimal point columns line up\n");
  11.  
  12. cout.precision(5);
  13. cout << "using streams" << endl;
  14. cout << scientific << M_PI << endl;
  15. cout << scientific << -M_PI << endl;
  16. cout << "decimal point columns do not line up" << endl;
  17. return 0;
  18. }
Success #stdin #stdout 0.02s 2724KB
stdin
Standard input is empty
stdout
using printf
 3.14159e+00
-3.14159e+00
decimal point columns line up
using streams
3.14159e+00
-3.14159e+00
decimal point columns do not line up