Advertisement
LabiinfaCibGyti

zah10+11.1

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