Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- double halfAvg(int arr[], int n);
- void printArray(int arr[], int n);
- int main()
- {
- int len;
- do
- {
- cout << "Enter arrays length: ";
- cin >> len;
- }
- while (len < 1 || len > 200 || (len % 2) != 0);
- int mas1[len], mas2[len], mas3[len], mas4[len];
- for (int i = 0; i < len; i++)
- {
- cout << "mas1[" << i << "]: ";
- cin >> mas1[i];
- }
- for (int i = 0; i < len; i++)
- {
- cout << "mas2[" << i << "]: ";
- cin >> mas2[i];
- }
- for (int i = 0; i < len; i++)
- {
- cout << "mas3[" << i << "]: ";
- cin >> mas3[i];
- }
- for (int i = 0; i < len; i++)
- {
- cout << "mas4[" << i << "]: ";
- cin >> mas4[i];
- }
- cout << "Half average mas1: " << halfAvg(mas1, len) << endl;
- cout << "Half average mas2: " << halfAvg(mas2, len) << endl;
- cout << "Half average mas3: " << halfAvg(mas3, len) << endl;
- cout << "Half average mas4: " << halfAvg(mas4, len) << endl;
- int m1[len], m2[len];
- for (int i = 0; i < len; i++)
- {
- m1[i] = mas1[i] + mas2[i];
- m2[i] = mas3[i] + mas4[i];
- }
- cout << "m1: ";
- printArray(m1, len);
- cout << "m2: ";
- printArray(m2, len);
- return 0;
- }
- double halfAvg(int arr[], int n)
- {
- double avg = 0;
- for (int i = 0; i < n / 2; i++)
- {
- avg += arr[i];
- }
- avg /= (n / 2);
- return avg;
- }
- void printArray(int arr[], int n)
- {
- for (int i = 0; i < n; i++)
- {
- cout << arr[i] << " ";
- }
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement