Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication1.cpp: определяет точку входа для консольного приложения.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- #include <Windows.h>
- #include <locale>
- #include <math.h>
- #include <conio.h>
- #define N 5
- using namespace std;
- void main()
- {
- setlocale(LC_ALL, "Russian");
- int A[N][N] = { 0 };
- int nul_st[N] = { 0 };
- int k, s, i, j, n;
- float sr;
- k = 0;
- s = 0;
- sr = 0;
- n = 0;
- cout << "Введите положительную квадратную матрицу 5X5 с нулевым столбцом и нулевой строкой: \n (Вводите числа, в которых не более четырех цифр)" << endl;
- for (i = 0; i < N; i++)
- {
- n = i + 1;
- cout << "Введите " << n << " строку: ";
- for (j = 0; j < N; j++)
- {
- cin >> setw(5) >> A[i][j];
- }
- }
- cout << endl;
- cout << "Матрица А " << endl;
- for (i = 0; i < N; i++)
- {
- for (j = 0; j < N; j++)
- {
- if (j + 1 < N) cout << setw(5) << A[i][j];
- else cout << setw(5) << A[i][j] << endl;
- }
- }
- for (i = 0; i < N; i++)
- {
- for (j = 0; j < N; j++)
- {
- sr += A[i][j];
- if (A[i][j] == 0)
- {
- k = i;
- s = j;
- }
- if (j + 1 == N)
- {
- sr /= N;
- A[k][s] = sr;
- nul_st[k] = A[k][s];
- A[k][s] = 0;
- sr = 0;
- }
- }
- }
- for (j = 0; j < N; j++)
- {
- for (i = 0; i < N; i++)
- {
- sr += A[i][j];
- if (A[i][j] == 0)
- {
- k = i;
- s = j;
- }
- if (i + 1 == N)
- {
- sr /= N;
- A[k][s] = sr;
- sr = 0;
- }
- }
- }
- for (i = 0; i < N; i++)
- {
- for (j = 0; j < N; j++)
- {
- if (A[i][j] == 0) A[i][j] = nul_st[i];
- }
- }
- cout << endl;
- cout << "Результат преобразований:" << endl;
- for (i = 0; i < N; i++)
- {
- for (j = 0; j < N; j++)
- {
- if (j + 1 < N) cout << setw(5) << A[i][j];
- else cout << setw(5) << A[i][j] << endl;
- }
- }
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement