fork download
  1. #include <stdio.h>
  2.  
  3. void g(double x)
  4. {
  5. int c = 0, i;
  6.  
  7. if (x < 0) {
  8. putchar('-');
  9. g(-x);
  10. return;
  11. }
  12. while (x < 1) {
  13. --c;
  14. x *= 10;
  15. }
  16. while (x >= 10) {
  17. ++c;
  18. x /= 10;
  19. }
  20. putchar(x + '0');
  21. putchar('.');
  22. x -= (int)x;
  23. x *= 10;
  24. for (i = 0; i < 6; ++i) {
  25. putchar(x + '0');
  26. x -= (int)x;
  27. x *= 10;
  28. }
  29. putchar('e');
  30. if (c < 0) {
  31. putchar('-');
  32. c *= -1;
  33. }
  34. putchar(c + '0');
  35. putchar('\n');
  36. return;
  37.  
  38. }
  39.  
  40. int main()
  41. {
  42. double f = 271.8281828;
  43. g(f);
  44. f /= 10000;
  45. g(f);
  46. f *= -1;
  47. g(f);
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0s 2292KB
stdin
Standard input is empty
stdout
2.718281e2
2.718281e-2
-2.718281e-2