Untitled
unknown
c_cpp
4 years ago
1.1 kB
6
Indexable
#include <iostream> #include <iomanip> #include <time.h> using namespace std; int main() { setlocale(LC_ALL, "rus"); srand(time(0)); int n, m, totalElement, amountOfSpecElements = 0; cout << "Введите размер матрицы" << endl; cin >> n >> m; int** array = new int* [n]; for (int i = 0; i < n; i++) { array[i] = new int[m]; } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) array[i][j] = rand() % 21 - 10; } cout << "Ваша матрица:" << endl; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cout << setw(4) << array[i][j]; } cout << endl; } for (int i = 0; i < m; i++) { int sumOfColumnElements = 0; for (int k = 0; k < n; k++) { sumOfColumnElements += array[k][i]; } for (int j = 0; j < n; j++) { totalElement = array[j][i]; if (sumOfColumnElements < 2 * totalElement) { amountOfSpecElements++; } } } cout << "Количество особых элементов: " << amountOfSpecElements; for (int i = 0; i < n; i++) { delete[] array[i]; } delete[] array; return 0; }
Editor is loading...