Advertisement
hookforehead

Untitled

Jan 22nd, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.30 KB | None | 0 0
  1. count int N = 300;
  2. char a[N + 1];
  3. //
  4. void input(char a[]) {
  5.     char st[N + 2];
  6.     scanf("%s", st);
  7.     int sign = 1, pos = 0;
  8.     if (st[0] == '+' || st[0] == '-') {
  9.         sign = (st[0] == '+' ? 1 : -1);
  10.         pos = 1;
  11.     }
  12.     int ia = 0, ist = strlen(st) - 1;
  13.     for (; ist >= pos;)
  14.         a[ia++] = st[ist--] - '0';
  15.     for (; ia < N; ia++)
  16.         a[ia] = 0;
  17.     if (sign == -1)
  18.         minus(a);
  19. }
  20. //
  21. void minus(char a[]) {
  22.     for (int i = 0; i < N; ++i)
  23.         a[i] = 9 - a[i];
  24.     for (int i = 0; i < N; ++i)
  25.         if (a[i] == 9)
  26.             a[i] = 0;
  27.         else {
  28.             a[i]++;
  29.             return;
  30.         }
  31. }
  32. //
  33. void output(char a[]) {
  34.     int sign = 1;
  35.     if (a[N - 1] >= 5) {
  36.         printf("-");
  37.         minus(a);
  38.         sign = -1;
  39.     }
  40.     int i = N - 1;
  41.     while (i > 0 && a[i] == 0)
  42.         --i;
  43.     for (; i >= 0; --i)
  44.         printf("%i", a[i]);
  45.     if (sign == -1)
  46.         minus(a);
  47. }
  48. //
  49. void add(char dest[], char a[], char b[]) {
  50.     int um = 0;
  51.     for (int i = 0; i < N; ++i) {
  52.         int t = a[i] + b[i] + um;
  53.         dest[i] = t % 10;
  54.         um = t / 10;
  55.     }
  56. }
  57. //
  58. void sub(char dest[], char a[], char b[]) {
  59.     minus(b);
  60.     add(dest, a, b);
  61.     minus(b);
  62. }
  63. //
  64. void mult(char dest[], char a[], char b[]) {
  65.     for (int i = 0; i < N; ++i)
  66.         dest[i] = 0;
  67.     for(int i = 0; i < N; ++i)
  68.         for (int j = 0; i + j < N; ++j) {
  69.             int t = a[i] * b[j] + dest[i + j];
  70.             dest[i+j] = t % 10;
  71.             dest[i + j + 1] += t / 10;
  72.         }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement