Advertisement
palmerstone

Decimal

Sep 22nd, 2011
508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <ctype.h>
  4. #include <math.h>
  5. #include <string.h>
  6.  
  7. int ar[10000], ar2[10000], ar3[10000];
  8.  
  9. int main()
  10. {
  11. int lol, t, i, j, k, l, a, b, c, d, x, y, r, z, flag, n, m, count, p;
  12.  
  13. for (; ;)
  14. {
  15. if (scanf("%d %d", &n, &m) == EOF) break;
  16.  
  17. count = 0, lol = n, c = 0, k = 0, flag = 0, l = 0, d = n / m;
  18.  
  19. n = n % m;
  20. for (p = 1; ;p++)
  21. {
  22. if (n == 0 || l > 2975) break;
  23.  
  24. for (; ;)
  25. {
  26. n = n * 10;
  27. if (n >= m)
  28. {
  29. x = n / m;
  30. y = n, z = x;
  31. n = n % m;
  32. for (r = 0; r < k; r++)
  33. {
  34. if (ar2[r] == y)
  35. {
  36. flag = 1;
  37. c = r;
  38. break;
  39. }
  40. }
  41. if (flag == 1) break;
  42.  
  43. for (; ;)
  44. {
  45. a = z / 10;
  46. ar[l++] = z % 10;
  47. z = a;
  48. if (a == 0) break;
  49. }
  50.  
  51. ar3[k] = l;
  52. ar2[k++] = y;
  53. break;
  54. }
  55. ar[l++] = 0;
  56. }
  57. if (flag == 1) break;
  58. }
  59.  
  60. z = 0;
  61. printf("%d/%d = %d.", lol, m, d);
  62.  
  63. if (flag == 0)
  64. {
  65. for (i = c; i < l; i++) printf("%d", ar[i]);
  66. puts("(0)");
  67. x = 1;
  68. }
  69.  
  70. else
  71. {
  72. for (i = 0; i < c; i++) printf("%d", ar[i]);
  73. printf("(");
  74. for (z = 1, i = c; i < l; i++,z++)
  75. {
  76. if (z == 51) break;
  77. printf("%d", ar[i]);
  78. }
  79. if (z == 51) puts("...)");
  80. else puts(")");
  81. x = l - ar3[c] + 1;
  82. }
  83. printf(" %d = number of digits in repeating cycle\n\n", x);
  84. }
  85. return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement