Advertisement
LabiinfaCibGyti

zahita10+11.8

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