View difference between Paste ID: RML0gTQP and snKp4MVQ
SHOW: | | - or go back to the newest paste.
1
#include <iostream>
2
#include <iomanip>
3
#include <cstdlib>
4
5
void add_arr (unsigned int *a1, size_t s1, unsigned int *a2, size_t s2, unsigned int *a3, size_t s3);
6
void out_arr (unsigned int *a1, size_t s);
7
void inp_arr (unsigned int *a1, size_t s);
8
9
using namespace std;
10
11
int main (void)
12
{
13
    const int max_size = 10;
14
    unsigned int arr1[max_size] = {0}, arr2[max_size] = {0}, arr3[max_size] = {0}; 
15
    int size;
16
    
17
    do
18
    {
19
        cout << "input size of arrays: ";
20
        cin >> size;
21
    } while (size > max_size);
22
    
23
    inp_arr(arr1, size);
24
    inp_arr(arr2, size);
25
    add_arr(arr1, size, arr2, size, arr3, size);
26-
    cout << "array3\n";
26+
   
27
    cout << "array1-> ";
28
    out_arr(arr1, size);
29
   
30
    cout << "array2-> ";
31
    out_arr(arr2, size);
32
   
33
    cout << "array3-> ";
34
    out_arr(arr3, size);
35
    
36
    system("pause");
37
    return 0;
38
}
39
40
41
void add_arr (unsigned int *a1, size_t s1, unsigned int *a2, size_t s2, unsigned int *a3, size_t s3)
42
{
43
    if ((s2 == s1) && (s3 >= s2))
44
    {
45
        for (size_t i = 0; i < s1; i++)
46
            a3[i] = a2[i] + a1[i];
47
        }
48
    else
49
    {
50
        cout << "wrong value" << endl;
51
    }
52
}
53
54
void out_arr (unsigned int *a1, size_t s)
55
{
56
    for (size_t i = 0; i < s; i++)
57
        cout << setw(5) << a1[i];
58
    cout << endl;
59
}
60
61
void inp_arr (unsigned int *a1, size_t s)
62
{
63
    for (size_t i = 0; i < s; i++)
64
    {
65
        cout << "input " << i << " element: ";
66
        cin >> a1[i];
67
    }
68
    cout << endl;
69
}