Advertisement
Guest User

V6Z2

a guest
Sep 29th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. void Chislo(int** a, int N, int M);
  8.  
  9. int main()
  10. {  
  11.     int N, M;
  12.     int **a;
  13.  
  14.     cout << "Vvedite N, M: ";
  15.     cin >> N >> M;
  16.     a = new int *[N];
  17.     for (int i = 0; i < N; i++)
  18.         a[i] = new int[M];
  19.  
  20.     for (int i = 0; i < N; i++)
  21.         for (int j = 0; j < M; j++) {
  22.             cout << "\t a[" << i + 1 << "][" << j + 1 << "] = ";
  23.             cin >> a[i][j];
  24.         }
  25.  
  26.     Chislo(a, N, M);
  27.  
  28.     cout << "\n Matrix A:" << endl;
  29.     for (int i = 0; i < N; i++) {
  30.         for (int j = 0; j < M; j++)
  31.             cout << "\t" << a[i][j];
  32.         cout << endl;
  33.     }
  34.     cout << endl;
  35.  
  36.     delete[]a;
  37.  
  38.     system("Pause");
  39.  
  40.     return 0;
  41. }
  42.  
  43.     void Chislo(int** a, int N, int M){
  44.     int min = a[0][0], chis, chis_n, chis_m;
  45.     for (int i = 0; i < N; i++) {
  46.         for (int j = 0; j < M; j++) {
  47.             if (a[i][j] < min)
  48.             {
  49.                 min = a[i][j];
  50.                 chis_n = i;
  51.                 chis_m = j;
  52.             }
  53.         }
  54.     }
  55.     chis = a[N- 1][M - 1];
  56.     a[chis_n][chis_m] = chis;
  57.     a[N - 1][M - 1] = min;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement