Advertisement
LabiinfaCibGyti

laba6.1

Dec 18th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <math.h>
  4. using namespace std;
  5. int _tmain(int argc, _TCHAR* argv[])
  6. {
  7.     int i, k=0;
  8.     double x[30], y[30], s=0, r;
  9.     setlocale(0,"rus");
  10.     for (i=0;i<30;i++)
  11.     {
  12.         x[i]=-100+rand()%200;
  13.         x[i]=x[i]/4;
  14.     }
  15.     for (i=0; i<30;i++)
  16.     {
  17.         cout<<"X["<<i+1<<"]= "<<x[i]<<endl;
  18.     }
  19.     for (i=0;i<30;i++)
  20.     {
  21.         if (x[i]>0)
  22.         {
  23.             y[k]=x[i];
  24.             k=k+1;
  25.             s=s+x[i];
  26.         }
  27.     }
  28.     cout<<endl;
  29.     for (i=0;i<k;i++)
  30.     {
  31.         cout<<"Y["<<i+1<<"]= "<<y[i]<<endl;
  32.     }
  33.     r=s/k;
  34.     cout<<"Среднее арифмитическое элементов массива Y= "<<r<<endl;
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement