Advertisement
LabiinfaCibGyti

zah10+11.8

Dec 18th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <math.h>
  4. using namespace std;
  5. double func(int b[25], int p)
  6. {  
  7.     int i;
  8.     double max=-3000000;
  9.     for (i=0; i<p; i++)
  10.         {
  11.             if (b[i]>max)
  12.             max=b[i];
  13.         }
  14. return (max);
  15. }
  16. void func2 (int a[5][5], int b[25],int *r)
  17. {
  18.     int i, j, k=3, p=0;
  19.     for (i=0; i<5; i++)
  20.     {
  21.         for (j=4; j>k; j--)
  22.         {
  23.             if(a[i][j]<0)
  24.             {
  25.                 b[p]=a[i][j];
  26.                 p=p+1;
  27.             }
  28.         }
  29.         k--;
  30.     }
  31.     *r=p;
  32. }
  33. double func3(int b[25], int p)
  34. {  
  35.     int i, s=0,r;
  36.     for (i=0; i<p; i++)
  37.         {
  38.             s=s+b[i];
  39.         }
  40.     r=s/p;
  41. return (r);
  42. }
  43. int _tmain(int argc, _TCHAR* argv[])
  44. {
  45.     int i, j,p;
  46.     int a[5][5], b[25];
  47.     setlocale (0,"rus");
  48.     for (i=0; i<5;i++)
  49.     {
  50.         for (j=0; j<5;j++)
  51.         {
  52.         a[i][j]=-10+rand()%20;
  53.         }
  54.     }
  55.     cout<<"Матрица 1"<<endl;
  56.         for (i=0; i<5;i++)
  57.         {
  58.             for (j=0; j<5; j++)
  59.             {
  60.                 cout<<a[i][j]<<"\t";
  61.             }
  62.             cout<<endl;
  63.         }
  64.         cout<<endl;
  65.         func2(a,b, &p);
  66.         for (i=0;i<p;i++)
  67.         {
  68.             cout<<b[i]<<endl;
  69.         }
  70.         cout<<endl;
  71.         cout<<"Max = "<<func(b,p)<<endl;
  72.         cout<<"Среднее арифмитическое = "<<func3(b,p)<<endl;
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement