Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. void In(int*, int);
  6. void Out(int*, int);
  7. void calculation(int*, int, double*);
  8. void cal(int*, int, double);
  9. int main()
  10. {
  11.     setlocale(LC_ALL, "RU");
  12.     int n;
  13.     double k=0;
  14.     cout << "Введите размер массива" << endl;
  15.     cin >> n;
  16.     int* a = new int[n];
  17.     In(a, n);
  18.     Out(a, n);
  19.     calculation(a, n, &k);
  20.     cal(a, n, k);
  21.     delete[]a;
  22.     a = NULL;
  23.     return 0;
  24. }
  25. void In(int* a, int n)
  26. {
  27.     cout << "Введите массив" << endl;
  28.     for (int i = 0; i < n; i++)
  29.     {
  30.         cin >> a[i];
  31.     }
  32. }
  33. void Out(int* a, int n)
  34. {
  35.     cout << "Введённый массив:" << endl;
  36.     for (int i = 0; i < n; i++)
  37.     {
  38.         cout << a[i]<<" ";
  39.     }
  40. }
  41. void calculation(int *a,int n,double *sr)
  42. {
  43.     double s = 0;
  44.     for (int i = 0; i < n; i++)
  45.     {
  46.         s += a[i];
  47.     }
  48.     cout << "Среднее значение = ";
  49.     *sr = s / n;
  50.     cout << *sr;
  51. }
  52. void cal(int *a,int n,double sr)
  53. {
  54.     double sum = 0;
  55.     for (int i = 0; i < n; i++)
  56.     {
  57.         if (a[i] < sr)
  58.             sum++;
  59.     }
  60.     cout << "Кол-во элементов меньше среднего значения:" << sum;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement