Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "Russian");
- int n, kol, min, minI;
- double sum = 0;
- sum = kol = min = minI = 0;
- cin >> n;
- int** a = new int* [n];
- for (int i = 0; i < n; i++) {
- a[i] = new int[n];
- for (int j = 0; j < n; j++)
- cin >> a[i][j];
- }
- cout << "Исходная матрица: " << endl;
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++)
- cout << a[i][j] << " ";
- cout << endl;
- }
- for (int i = 0; i < n; i++)
- for (int j = 0; j < n; j++)
- if (a[i][j] < 0) {
- kol++;
- sum += a[i][j];
- }
- cout << "Среднее арифметическое отрицательных элементов: ";
- if (kol == 0)
- cout << "Отрицатльных чисел нет" << endl;
- else
- cout << sum / kol << endl;
- sum = 0;
- for (int j = 0; j < n; j++)
- sum += a[1][j] * a[1][j];
- cout << "Сумма квадратов 2-й строки: " << sum << endl;
- for (int i = 0; i < n; i++)
- for (int j = 0; j < n; j++)
- if (a[i][j] < min) {
- min = a[i][j];
- minI = i;
- }
- for (int j = 0; j < n; j++)
- swap(a[minI][j], a[n - 1][j]);
- cout << "Матрица после смены строк местами: " << endl;
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++)
- cout << a[i][j] << " ";
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement