Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <ctype.h>
- #include <math.h>
- #include <string.h>
- int ar[10000], ar2[10000], ar3[10000];
- int main()
- {
- int lol, t, i, j, k, l, a, b, c, d, x, y, r, z, flag, n, m, count, p;
- for (; ;)
- {
- if (scanf("%d %d", &n, &m) == EOF) break;
- count = 0, lol = n, c = 0, k = 0, flag = 0, l = 0, d = n / m;
- n = n % m;
- for (p = 1; ;p++)
- {
- if (n == 0 || l > 2975) break;
- for (; ;)
- {
- n = n * 10;
- if (n >= m)
- {
- x = n / m;
- y = n, z = x;
- n = n % m;
- for (r = 0; r < k; r++)
- {
- if (ar2[r] == y)
- {
- flag = 1;
- c = r;
- break;
- }
- }
- if (flag == 1) break;
- for (; ;)
- {
- a = z / 10;
- ar[l++] = z % 10;
- z = a;
- if (a == 0) break;
- }
- ar3[k] = l;
- ar2[k++] = y;
- break;
- }
- ar[l++] = 0;
- }
- if (flag == 1) break;
- }
- z = 0;
- printf("%d/%d = %d.", lol, m, d);
- if (flag == 0)
- {
- for (i = c; i < l; i++) printf("%d", ar[i]);
- puts("(0)");
- x = 1;
- }
- else
- {
- for (i = 0; i < c; i++) printf("%d", ar[i]);
- printf("(");
- for (z = 1, i = c; i < l; i++,z++)
- {
- if (z == 51) break;
- printf("%d", ar[i]);
- }
- if (z == 51) puts("...)");
- else puts(")");
- x = l - ar3[c] + 1;
- }
- printf(" %d = number of digits in repeating cycle\n\n", x);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement