-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05-1-array.cpp
More file actions
44 lines (36 loc) · 946 Bytes
/
Copy path05-1-array.cpp
File metadata and controls
44 lines (36 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
using namespace std;
int main()
{
size_t len;
const size_t MAX_SIZE = 10;
int a[MAX_SIZE], b[MAX_SIZE], res[MAX_SIZE];
cout << "Введите длину массива: ";
cin >> len;
if (len > MAX_SIZE)
{
cerr << "Ошибка: длина не может быть больше " << MAX_SIZE << endl;
return 1;
}
cout << "Введите элементы массива a (через пробел): ";
for (size_t i = 0; i < len; i++)
{
cin >> a[i];
}
cout << "Введите элементы массива b (через пробел): ";
for (size_t i = 0; i < len; i++)
{
cin >> b[i];
}
// res = a + b
for (size_t i = 0; i < len; i++)
{
res[i] = a[i] + b[i];
}
cout << "Массив res: ";
for (size_t i = 0; i < len; i++)
{
cout << res[i] << ' ';
}
cout << endl;
}