Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <cmath>
- using namespace std;
- int main() {
- setlocale(LC_ALL, "Russian");
- int *a, n, x, *b, *c;
- srand((unsigned)time(NULL));
- cout << "Введите кол-во цифр в числе" << endl;
- cin >> n;
- a = new int[n]; // массив 1
- b = new int[n]; // массив 2
- c = new int[n + 1]; // массив после сложения
- if (n > 20) {
- for (int i = 0; i < n; i++) { // Заполняем массивы
- a[i] = rand() % 9 + 1;
- b[i] = rand() % 9 + 1;
- };
- cout << "Первое число ";
- for (int i = 0; i < n; i++) { // Выводим массив 1
- cout << a[i];
- }
- cout << endl;
- cout << "Второе число ";
- for (int i = 0; i < n; i++) { // Выводим массив 2
- cout << b[i];
- }
- cout << endl;
- for (int i = 0; i < n; i++) { // Складываем числа
- c[i] = a[i] + b[i];
- }
- for (int i = n - 1; i > 0; i--) {
- c[i - 1] = c[i - 1] + c[i] / 10;
- c[i] = c[i] % 10;
- }
- cout << "Сумма двух чисел = ";
- for (int i = 0; i < n; i++) { // Вывод
- cout << c[i];
- }
- }
- else {
- cout << "Недостаточно цифр в числе";
- }
- cout << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement