Advertisement
Kentoo

N#4

Dec 21st, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.98 KB | None | 0 0
  1. // ConsoleApplication1.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <iomanip>
  7. #include <cmath>
  8. #include <Windows.h>
  9. #include <locale>
  10. #include <math.h>
  11. #include <conio.h>
  12.  
  13. #define N 5
  14.  
  15. using namespace std;
  16. void main()
  17. {
  18.     setlocale(LC_ALL, "Russian");
  19.     int A[N][N] = { 0 };
  20.     int nul_st[N] = { 0 };
  21.     int k, s, i, j, n;
  22.     float sr;
  23.     k = 0;
  24.     s = 0;
  25.     sr = 0;
  26.     n = 0;
  27.     cout  << "Введите положительную квадратную матрицу 5X5 с нулевым столбцом и нулевой строкой: \n (Вводите числа, в которых не более четырех цифр)" << endl;
  28.     for (i = 0; i < N; i++)
  29.     {
  30.         n = i + 1;
  31.         cout << "Введите " << n << " строку: ";
  32.         for (j = 0; j < N; j++)
  33.         {
  34.             cin >> setw(5)  >> A[i][j];
  35.         }
  36.     }
  37.     cout << endl;
  38.     cout << "Матрица А " << endl;
  39.     for (i = 0; i < N; i++)
  40.     {
  41.         for (j = 0; j < N; j++)
  42.         {
  43.             if (j + 1 < N) cout << setw(5) << A[i][j];
  44.             else cout << setw(5) << A[i][j] << endl;
  45.         }
  46.     }
  47.     for (i = 0; i < N; i++)
  48.     {
  49.         for (j = 0; j < N; j++)
  50.         {
  51.             sr += A[i][j];
  52.             if (A[i][j] == 0)
  53.             {
  54.                 k = i;
  55.                 s = j;
  56.             }
  57.             if (j + 1 == N)
  58.             {
  59.                 sr /= N;
  60.                 A[k][s] = sr;
  61.                 nul_st[k] = A[k][s];
  62.                 A[k][s] = 0;
  63.                 sr = 0;
  64.             }
  65.         }
  66.     }
  67.     for (j = 0; j < N; j++)
  68.     {
  69.         for (i = 0; i < N; i++)
  70.         {
  71.             sr += A[i][j];
  72.             if (A[i][j] == 0)
  73.             {
  74.                 k = i;
  75.                 s = j;
  76.             }
  77.             if (i + 1 == N)
  78.             {
  79.                 sr /= N;
  80.                 A[k][s] = sr;
  81.                 sr = 0;
  82.             }
  83.         }
  84.     }
  85.     for (i = 0; i < N; i++)
  86.     {
  87.         for (j = 0; j < N; j++)
  88.         {
  89.             if (A[i][j] == 0) A[i][j] = nul_st[i];
  90.         }
  91.     }
  92.     cout << endl;
  93.     cout << "Результат преобразований:" << endl;
  94.     for (i = 0; i < N; i++)
  95.     {
  96.         for (j = 0; j < N; j++)
  97.         {
  98.             if (j + 1 < N) cout << setw(5) << A[i][j];
  99.             else cout << setw(5) << A[i][j] << endl;
  100.         }
  101.     }
  102.     _getch();
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement