Last active
January 9, 2019 19:38
-
-
Save CloneBoiii/3a0eccd6145e23fbc4b6f5cbe2319890 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "pch.h" | |
| #include <iostream> | |
| #include "locale.h" | |
| using namespace std; | |
| int main() | |
| { | |
| setlocale(LC_ALL, "Russian"); | |
| int a[20][20], i, j, n; | |
| int b[40]; | |
| cout << "Введите количество строк и столбцов: "; | |
| cin >> n; | |
| for (i = 0; i < n; i++) | |
| { | |
| for (j = 0; j < n; j++) | |
| { | |
| cout << "Введите элемент: "; | |
| cin >> a[i][j]; | |
| } | |
| } | |
| cout << "Матрица: " << endl; | |
| for (i = 0; i < n; i++) | |
| { | |
| for (j = 0; j < n; j++) | |
| cout << a[i][j] << "\t"; | |
| cout << endl; | |
| } | |
| for (j = 0; j < n; j++) //считаем кол-во отрицательных чисел в каждом столбце | |
| { | |
| int S = 0, k = 0; | |
| for (i = 0; i < n; i++) | |
| { | |
| if (a[i][j] < 0) k++; | |
| S += a[i][j]; | |
| } | |
| if (k == 0) cout << "Сумма чисел в " << j + 1 << " столбце равна " << S << endl; //если она равна нулю выводим сумму | |
| else cout << "В " << j + 1 << " столбце встречаются отрицательные числа" << endl; //если нет, то это | |
| } | |
| int index = 0, max = 0, sumr = 0, suml = 0; | |
| for (int i = 1; i < n - 1; i++) | |
| { | |
| for (int j = 0; j < n - i; j++) | |
| { | |
| sumr += a[i + j][j]; | |
| suml += a[j][j + i]; | |
| } | |
| b[index] = sumr; | |
| b[index + 1] = suml; | |
| sumr = 0; | |
| suml = 0; | |
| index += 2; | |
| } | |
| int max_sum = b[0]; | |
| for (int k = 1; k < 2 * n - 4; k++) | |
| max_sum = max_sum < b[k] ? b[k] : max_sum; | |
| cout << "Максимум суммы элементов: " << max_sum << endl; | |
| cin.get(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment