Skip to content

Instantly share code, notes, and snippets.

@CloneBoiii
Last active December 19, 2018 16:12
Show Gist options
  • Save CloneBoiii/428e9bc12656a8bd1d97274d26b86ceb to your computer and use it in GitHub Desktop.
Save CloneBoiii/428e9bc12656a8bd1d97274d26b86ceb to your computer and use it in GitHub Desktop.
#include "pch.h"
#include <iostream>
#include "locale.h"
using namespace std;
int main()
{
setlocale (LC_ALL, "Russian");
int a[20][20], i, j, n;
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; //если нет, то это
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment