Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "Russian");
- int n;
- int gd = 0, ngd = 0, pgd = 0, k = 0;
- cout << "Введите размерность n: ";
- cin >> n;
- float** mat = new float* [n]; //объявление матрицы n x n
- for (int i = 0; i < n; i++)
- mat[i] = new float[n];
- for (int i = 0; i < n; i++)
- for (int j = 0; j < n; j++)
- cin >> mat[i][j];
- cout << "Матрица:" << endl;
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- cout << setw(4) << mat[i][j] << " ";
- cout << endl;
- }
- for (int i = 0; i < n; i++)
- if (mat[i][0] < 0)
- {
- k = k + 1;
- for (int y = 0; y < n; y++)
- for (int j = 0; j < n; j++)
- {
- if (y = j) gd = gd + mat[y][j];
- if (y > j) pgd = pgd + mat[y][j];
- if (y < j) ngd = ngd + mat[y][j];
- }
- break;
- }
- if (k == 0) cout << "С отрицательного не начинается!" << endl;
- else
- {
- cout << "Сумма элементов на главной диагонале равна: " << gd << endl;
- cout << "Сумма элементов под главной диагональю равна: " << pgd << endl;
- cout << "Сумма элементов над главной диагональю равна: " << ngd << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement