Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4. int main()
  5. {
  6. setlocale(LC_ALL, "Russian");
  7. int n;
  8. int gd = 0, ngd = 0, pgd = 0, k = 0;
  9. cout << "Введите размерность n: ";
  10. cin >> n;
  11.  
  12. float** mat = new float* [n]; //объявление матрицы n x n
  13. for (int i = 0; i < n; i++)
  14. mat[i] = new float[n];
  15.  
  16. for (int i = 0; i < n; i++)
  17. for (int j = 0; j < n; j++)
  18. cin >> mat[i][j];
  19.  
  20. cout << "Матрица:" << endl;
  21. for (int i = 0; i < n; i++)
  22. {
  23. for (int j = 0; j < n; j++)
  24. cout << setw(4) << mat[i][j] << " ";
  25. cout << endl;
  26. }
  27. for (int i = 0; i < n; i++)
  28.  
  29. if (mat[i][0] < 0)
  30. {
  31. k = k + 1;
  32. for (int y = 0; y < n; y++)
  33.  
  34. for (int j = 0; j < n; j++)
  35. {
  36. if (y = j) gd = gd + mat[y][j];
  37. if (y > j) pgd = pgd + mat[y][j];
  38. if (y < j) ngd = ngd + mat[y][j];
  39. }
  40.  
  41. break;
  42. }
  43.  
  44. if (k == 0) cout << "С отрицательного не начинается!" << endl;
  45. else
  46. {
  47. cout << "Сумма элементов на главной диагонале равна: " << gd << endl;
  48. cout << "Сумма элементов под главной диагональю равна: " << pgd << endl;
  49. cout << "Сумма элементов над главной диагональю равна: " << ngd << endl;
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement