Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. #define N 10
  6.  
  7. void init(int a[N]) {
  8.     for (int i = 0; i < N; ++i)
  9.         a[i] = rand() % 10;
  10. }
  11.  
  12. void print(int a[N]) {
  13.     for (int i = 0; i < N; ++i)
  14.         cout << a[i] << " ";
  15.     cout << endl;
  16. }
  17.  
  18. double average(int a[N]) {
  19.     double s = 0;
  20.     int k = 0;
  21.     for (int i = 0; i < N; ++i)
  22.         if (a[i] > 0) {
  23.             s += a[i];
  24.             ++k;
  25.         }
  26.     return s / k;
  27. }
  28.  
  29. int main() {
  30.     setlocale(LC_ALL, "rus");
  31.     int a[N], b[N];
  32.     init(a);
  33.     print(a);
  34.     init(b);
  35.     print(b);
  36.     double x = average(a);
  37.     cout << "Среднее арифметическое массива a: " << x << endl;
  38.     double y = average(b);
  39.     cout << "Среднее арифметическое массива b: " << y << endl;
  40.     cout << "Произведение средних: " << x * y << endl;
  41.     system("pause");
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement