Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int power(int a, int n) {
  5.     int number = 1;
  6.  
  7.     while (n) {
  8.         if (n & 1) {
  9.             number *= a;
  10.             n--;
  11.         }
  12.         else {
  13.             a *= a;
  14.             n >>= 1;
  15.         }
  16.     }
  17.  
  18.     return number;
  19. }
  20.  
  21. int number(int *array, int size) {
  22.     int length = size / sizeof(array[0]);
  23.     int sum = array[0];
  24.  
  25.     for (int i = 1; i != length; i++)
  26.         sum += array[i] * power(10, i);
  27.  
  28.     return sum;
  29. }
  30.  
  31. int mul(int *a, int *b, int size_a, int size_b) {
  32.     return number(a, size_a) * number(b, size_b);
  33. }
  34.  
  35. int main() {
  36.     int a[3] = {1, 2, 3};
  37.     int b[3] = {4, 5, 6};
  38.  
  39.     cout << mul(a, b, sizeof(a), sizeof(b)) << endl;
  40.  
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement