Advertisement
LabiinfaCibGyti

zahFedya

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