fork(2) download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main(void) {
  5. double x;
  6. while(scanf("%lf", &x)==1) {
  7. if (x==0 || x!=x) {
  8. printf("%g\n", x);
  9. continue;
  10. }
  11. int exponent10 = floor(log10(fabs(x)));
  12. double mantisa10 = x / pow10(exponent10);
  13. if (fabs(mantisa10)>=9.999995) {
  14. exponent10++;
  15. mantisa10/=10;
  16. }
  17. printf("%ge%+d\n", mantisa10, exponent10);
  18. }
  19. return 0;
  20. }
  21.  
Success #stdin #stdout 0s 2300KB
stdin
9.99999
9.999999
9.99999999999
9.999995
9.9999949
1.0e0
1.0e-5
1.0e5
5.005
-50000.4
2.99999e33
0.0000000000001000001
-3e-33
stdout
9.99999e+0
1e+1
1e+1
1e+1
9.99999e+0
1e+0
1e-5
1e+5
5.005e+0
-5.00004e+4
2.99999e+33
1e-13
-3e-33