Guest User

Untitled

a guest
Oct 18th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.41 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. void set(int a[], int b[], int c[], int d[]);
  4. void mult(int a[], int b[], int c[], int d[], int index, int index2);
  5. void copy(int c[], int j);
  6. void madd(int d[], int c[]);
  7. void add(int a[], int b[], int c[], int index);
  8.  
  9. const int size = 10000;
  10. int main ()
  11. {
  12.     int index, index2, *m, n, o, p, f;
  13.     index = 0;
  14.     index2= 0;
  15.     int a[size], b[size], c[size], d[size];
  16.         set(a, b, c, d);
  17.         m = new int(0);
  18.         cout << "Please enter in 2 numbers seperated by a space: ";
  19.         cin >> m >> o;
  20.         if (o > m)
  21.         {
  22.             int temp;
  23.             temp = o;
  24.             o = m;
  25.             m = temp;
  26.         }
  27.         for (index; m > 0; index++)
  28.         {
  29.             n = m % 10;
  30.             m = m / 10;
  31.             a[index] = n;
  32.         }
  33.         for (index2; o > 0; index2++)
  34.         {
  35.             p = o % 10;
  36.             o = o / 10;
  37.             b[index2] = p;
  38.         }
  39.         mult(a, b, c, d, index, index2);       
  40.         add(a, b, c, index);
  41.         for ( f = (size - 1); f >= 0; f--)
  42.         {
  43.             if (d[f] != 0)
  44.                 break;
  45.         }
  46.         for (int fun = (f); fun >= 0; fun--)
  47.         {
  48.             cout << d[fun];
  49.         }
  50.         cout << endl;
  51.         for (f = (size - 1); f >= 0; f--)
  52.         {
  53.             if (c[f] != 0)
  54.                 break;
  55.         }
  56.         for (int fun = (f); fun >= 0; fun--)
  57.         {
  58.             cout << c[fun];
  59.         }
  60. }
  61. void set(int a[], int b[], int c[], int d[])
  62. {
  63.     for (int i = 0; i < size; i++)
  64.     {
  65.         a[i] = 0;
  66.         b[i] = 0;
  67.         c[i] = 0;
  68.         d[i] = 0;
  69.     }
  70. }
  71. void mult(int a[], int b[], int c[], int d[], int index, int index2)
  72. {
  73.     for (int j = 0; j < index2; j++)
  74.     {
  75.         int z = 0;
  76.         for (int i = 0; i <= (index); i++)
  77.         {
  78.             c[i] =  (a[i] * b[j]) + z;
  79.             if (c[i] > 9)
  80.             {
  81.                 z = (c[i] / 10);
  82.                 c[i] = (c[i] % 10);
  83.             }
  84.             else
  85.             {
  86.                 z = 0;
  87.             }
  88.         }
  89.         if (j > 0)
  90.             copy(c, j);
  91.         madd(d, c);
  92.  
  93.     }
  94. }
  95. void copy(int c[], int j)
  96. {
  97.     int *p;
  98.  
  99.     p = new int[1000000];
  100.     for (int i = 0; i < size; i++)
  101.     {
  102.         p[i] = 0;
  103.     }
  104.     for (int i = 0; i < size; i++)
  105.     {
  106.         p[i+j] = c[i];
  107.     }
  108.     for (int i = 0; i < size; i++)
  109.     {
  110.         c[i] = p[i];
  111.     }
  112.     delete [] p;
  113. }
  114. void madd(int d[], int c[])
  115. {
  116.     int z;
  117.     z = 0;
  118.     for (int i = 0; i < size; i++)
  119.     {
  120.         d[i] = d[i] + c[i] + z;
  121.         if (d[i] > 9)
  122.         {
  123.             z = (d[i] / 10);
  124.             d[i] = (d[i] % 10);
  125.         }
  126.         else
  127.         {
  128.             z = 0;
  129.         }
  130.     }
  131.     for (int i = 0; i < size; i++)
  132.     {
  133.         c[i] = 0;
  134.     }
  135. }
  136. void add(int a[], int b[], int c[], int index)
  137. {
  138.     int z = 0;
  139.     for (int i = 0; i <= index; i++)
  140.     {
  141.         c[i] = a[i] + b[i] + z;
  142.         if (c[i] > 9)
  143.         {
  144.             z = (c[i] / 10);
  145.             c[i] = (c[i] % 10);
  146.         }
  147.         else
  148.         {
  149.             z = 0;
  150.         }
  151.     }
  152. }
Add Comment
Please, Sign In to add comment