fork(3) download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define x(k) (((k) >= 0) ? in[strlen(in) - 1 - (k)] - '0' : 0)
  5. void esr(char *in, char *out, int len)
  6. {
  7. int n, i, a, r, q, z, t;
  8. char *p;
  9.  
  10. p = out;
  11. n = ((len - 1) / 2) * 2;
  12. r = 0;
  13. q = 0;
  14. a = 0;
  15. z = 10 * x(n + 1) + x(n);
  16. i = n - 1;
  17.  
  18. do {
  19. for(a = 0; a <= 9; a++) {
  20. if ((10 * q + a) * a <= z && z < (10 * q + (a + 1)) * (a + 1))
  21. break;
  22. }
  23. if (i == -3)
  24. *p++ = '.';
  25. *p++ = a + '0';
  26. r = (10 * q + a) * a;
  27. q = 10 * q + 2 * a;
  28. z = 100 * (z - r) + 10 * x(i);
  29. i--;
  30. z = z + x(i);
  31. i--;
  32. } while (i >= -3);
  33. *p = '\0';
  34. return;
  35. }
  36.  
  37. #define N 8
  38. int main()
  39. {
  40. static char in[N + 1], out[N];
  41. int n;
  42. char *p;
  43.  
  44. printf(">");
  45. fgets(in + 1, N, stdin);
  46. in[0] = '0';
  47. for (p = in; *p != '\n'; p++);
  48. *p = '\0';
  49. n = strlen(in + 1);
  50.  
  51. if (n % 2 == 0)
  52. esr(in + 1, out, n);
  53. else
  54. esr(in, out, n);
  55.  
  56. printf("%s\n", out, n);
  57. return 0;
  58. }
  59. /* end */
  60.  
Runtime error #stdin #stdout 0.02s 1724KB
stdin
Standard input is empty
stdout
Standard output is empty