Advertisement
MSlomiany

Untitled

Apr 7th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     setlocale(LC_ALL, "");
  9.     int m, n, i, j, a;
  10.     float max = 0, min = 0, pom = 0;
  11.     float A[10][10];
  12.     int maxi = 0, maxj = 0, mini = 0, minj = 0;
  13.  
  14.     cout << "Podaj ilość wierszy: ";
  15.     cin >> m;
  16.     cout << "Podaj ilość kolumn: ";
  17.     cin >> n;
  18.     cout << ">> Podaj elementy macierzy << " << endl;
  19.     for (i = 0; i < m; i++)
  20.     {
  21.         for (j = 0; j < n; j++)
  22.         {
  23.             cout << "A[" << i + 1 << "][" << j + 1 << "]: ";
  24.             cin >> A[i][j];
  25.         }
  26.     }
  27.  
  28.     cout << ">> Macierz A <<" << endl;
  29.     for (i = 0; i < m; i++)
  30.     {
  31.         for (j = 0; j < n; j++)
  32.         {
  33.             cout << fixed << setprecision(2) << setw(7) << A[i][j];
  34.         }
  35.         cout << "\n";
  36.     }
  37.  
  38.     cout << "Podaj numer wiersza: ";
  39.     cin >> a;
  40.     max = A[a - 1][0];
  41.     min = A[a - 1][0];
  42.     for (j = 0; j < n; j++)
  43.     {
  44.         if (A[a - 1][j] > max)
  45.         {
  46.             max = A[a - 1][j];
  47.             maxj = j;
  48.         }
  49.         if (A[a - 1][j] < min)
  50.         {
  51.             min = A[a - 1][j];
  52.             minj = j;
  53.         }
  54.     }
  55.  
  56.     cout << "Wartość maksymalna w wierszu " << a << ": " << max << endl;
  57.     cout << "Wartość minimalna w wierszu " << a << ": " << min << endl;
  58.  
  59.     pom = A[a-1][maxj];
  60.     A[a-1][maxj] = A[a-1][minj];
  61.     A[a-1][minj] = pom;
  62.  
  63.     cout << ">> Macierz A po zamianie <<" << endl;
  64.     for (i = 0; i < m; i++)
  65.     {
  66.         for (j = 0; j < n; j++)
  67.         {
  68.             cout << fixed << setprecision(2) << setw(7) << A[i][j];
  69.         }
  70.         cout << "\n";
  71.     }
  72.  
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement