Advertisement
F0ntasTiSh

Untitled

Nov 23rd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     setlocale(LC_ALL, "Russian");
  9.     int *a, n, x, *b, *c;
  10.     srand((unsigned)time(NULL));
  11.     cout << "Введите кол-во цифр в числе" << endl;
  12.     cin >> n;
  13.     a = new int[n];    // массив 1
  14.     b = new int[n];   // массив 2
  15.     c = new int[n + 1]; // массив после сложения
  16.     if (n > 20) {
  17.         for (int i = 0; i < n; i++) {    // Заполняем массивы
  18.             a[i] = rand() % 9 + 1;
  19.             b[i] = rand() % 9 + 1;
  20.         };
  21.         cout << "Первое число ";
  22.         for (int i = 0; i < n; i++) {   // Выводим массив 1
  23.             cout << a[i];
  24.         }
  25.         cout << endl;
  26.         cout << "Второе число ";
  27.         for (int i = 0; i < n; i++) {   // Выводим массив 2
  28.             cout << b[i];
  29.         }
  30.         cout << endl;
  31.         for (int i = 0; i < n; i++) {    // Складываем числа
  32.             c[i] = a[i] + b[i];
  33.         }
  34.         for (int i = n - 1; i > 0; i--) {
  35.             c[i - 1] = c[i - 1] + c[i] / 10;
  36.             c[i] = c[i] % 10;
  37.         }
  38.         cout << "Сумма двух чисел = ";
  39.         for (int i = 0; i < n; i++) {   // Вывод
  40.             cout << c[i];
  41.         }
  42.     }
  43.     else {
  44.         cout << "Недостаточно цифр в числе";
  45.     }
  46.     cout << endl;
  47.     system("pause");
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement