LabiinfaCibGyti

zahita10+11.2

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