Advertisement
Guest User

Untitled

a guest
Feb 18th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. // ConsoleApplication1.cpp : Defines the entry point for the console application.
  2. //
  3. #include "stdafx.h"
  4. #include <iostream>
  5. #include <conio.h>
  6. #include <iostream>
  7. #include <ctime>
  8. #include <conio.h>
  9. #include <math.h>
  10. #include <stdio.h>
  11. #include <conio.h>
  12. #include <Windows.h>
  13. using namespace std;
  14.  
  15.  
  16. const int n = 10;
  17. const int m = 10;
  18.  
  19.  
  20. void Replace(int **Matrix, int n, int m)
  21. {
  22.     int Max;
  23.     for (int i = 0; i < n; i++)
  24.     {
  25.         Max = 0;
  26.         for (int j = 0; j < m; j++)
  27.         {
  28.             if (Matrix[i][Max] < Matrix[i][j])  Max = j;
  29.         }
  30.         if (Max != i)
  31.         {
  32.             int temp = Matrix[i][Max];
  33.             Matrix[i][Max] = Matrix[i][i];
  34.             Matrix[i][i] = temp;
  35.         }
  36.     }
  37. }
  38.  
  39. void inPut(int **Matrix,int n,int m)
  40. {
  41.     for (int i = 0; i < n;i++)
  42.     {
  43.         for (int j = 0; j < m; j++)
  44.         {
  45.             Matrix[i][j] = rand() % 10;
  46.         }
  47.     }
  48. }
  49.  
  50. void outPut(int **Matrix, int n, int m)
  51. {
  52.     cout << "Матрица" << endl;
  53.     for (int i = 0; i < n; i++)
  54.     {
  55.         for (int j = 0; j < m; j++)
  56.         {
  57.             cout << Matrix[i][j] << "    ";
  58.         }
  59.         cout << endl;
  60.     }
  61.     cout << endl;
  62. }
  63.  
  64. int main()
  65. {
  66.     setlocale(LC_ALL, "Russian");
  67.  
  68.     int n, m;
  69.     cout << "Введите число n: ";
  70.     cin >> n;
  71.     cout << "Введите число m: ";
  72.     cin >> m;
  73.     int **Mat;
  74.     Mat = new int*[n];
  75.     for (int j = 0; j < m; j++) Mat[j] = new int[m];
  76.  
  77.     inPut(Mat, n, m);
  78.     outPut(Mat, n, m);
  79.     Replace(Mat, n, m);
  80.     outPut(Mat, n, m);
  81.  
  82.     system("pause");
  83.  
  84.     return 1;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement