Advertisement
vencinachev

DidiProgram

Jan 3rd, 2021
962
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. double halfAvg(int arr[], int n);
  6. void printArray(int arr[], int n);
  7.  
  8. int main()
  9. {
  10.     int len;
  11.     do
  12.     {
  13.         cout << "Enter arrays length: ";
  14.         cin >> len;
  15.     }
  16.     while (len < 1 || len > 200 || (len % 2) != 0);
  17.  
  18.     int mas1[len], mas2[len], mas3[len], mas4[len];
  19.  
  20.     for (int i = 0; i < len; i++)
  21.     {
  22.         cout << "mas1[" << i << "]: ";
  23.         cin >> mas1[i];
  24.     }
  25.  
  26.     for (int i = 0; i < len; i++)
  27.     {
  28.         cout << "mas2[" << i << "]: ";
  29.         cin >> mas2[i];
  30.     }
  31.  
  32.     for (int i = 0; i < len; i++)
  33.     {
  34.         cout << "mas3[" << i << "]: ";
  35.         cin >> mas3[i];
  36.     }
  37.  
  38.     for (int i = 0; i < len; i++)
  39.     {
  40.         cout << "mas4[" << i << "]: ";
  41.         cin >> mas4[i];
  42.     }
  43.  
  44.     cout << "Half average mas1: " << halfAvg(mas1, len) << endl;
  45.     cout << "Half average mas2: " << halfAvg(mas2, len) << endl;
  46.     cout << "Half average mas3: " << halfAvg(mas3, len) << endl;
  47.     cout << "Half average mas4: " << halfAvg(mas4, len) << endl;
  48.  
  49.     int m1[len], m2[len];
  50.  
  51.     for (int i = 0; i < len; i++)
  52.     {
  53.         m1[i] = mas1[i] + mas2[i];
  54.         m2[i] = mas3[i] + mas4[i];
  55.     }
  56.  
  57.     cout << "m1: ";
  58.     printArray(m1, len);
  59.  
  60.     cout << "m2: ";
  61.     printArray(m2, len);
  62.  
  63.     return 0;
  64. }
  65.  
  66. double halfAvg(int arr[], int n)
  67. {
  68.     double avg = 0;
  69.     for (int i = 0; i < n / 2; i++)
  70.     {
  71.         avg += arr[i];
  72.     }
  73.     avg /= (n / 2);
  74.     return avg;
  75. }
  76.  
  77. void printArray(int arr[], int n)
  78. {
  79.     for (int i = 0; i < n; i++)
  80.     {
  81.         cout << arr[i] << " ";
  82.     }
  83.     cout << endl;
  84. }
  85.  
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement