Advertisement
ProgNeo

Untitled

Nov 23rd, 2021 (edited)
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. #include <algorithm>
  2. #include <vector>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8. setlocale(LC_ALL, "rus");
  9.  
  10. float** L;
  11. int m, n;
  12. float min, sum = 0, temp;
  13. int n_of_min, temp_n{};
  14.  
  15. cout << "Введите количество строк(m) и количество столбцов(n) (1 < (m, n) < 10): ";
  16. while (!(cin >> m >> n) || (cin.peek() != '\n') || (m < 2 || m > 9) || (n < 2 || n > 9)) {
  17. cin.clear();
  18. while (cin.get() != '\n');
  19. cout << "Неверный ввод! m, n = ";
  20. }
  21.  
  22. L = new float* [m];
  23. for (int i = 0; i < m; i++) {
  24. L[i] = new float[n];
  25. for (int k = 0; k < n; k++) {
  26. cout << "L[" << i + 1 << "][" << k + 1 << "] = ";
  27. while (!(cin >> L[i][k]) || (cin.peek() != '\n') || L[i][k] < -100 || L[i][k] > 100) {
  28. cin.clear();
  29. while (cin.get() != '\n');
  30. cout << "L[" << i + 1 << "][" << k + 1 << "] = ";
  31. }
  32. }
  33. }
  34.  
  35. cout << "\nПолученная матрица:\n";
  36. for (int i = 0; i < m; i++) {
  37. for (int j = 0; j < n; j++) {
  38. cout << L[i][j] << "\t";
  39. }
  40. cout << "\n";
  41. }
  42.  
  43. cout << "\nСтроки со элементами меньше нуля: ";
  44. for (int i = 0; i < m; i++) {
  45. for (int j = 0; j < n; j++) {
  46. if (L[i][j] < 0) {
  47. cout << i + 1 << " ";
  48. break;
  49. }
  50. }
  51. }
  52.  
  53. for (int j = 0; j < n; j++) {
  54. min = -100, n_of_min = -1;
  55. for (int i = j; i < n; i++) {
  56. temp = 100;
  57. for (int k = 0; k < m; k++) {
  58. if (L[k][i] <= temp) {
  59. temp = L[k][i];
  60. temp_n = i;
  61. }
  62. }
  63. if (temp >= min) {
  64. min = temp;
  65. n_of_min = temp_n;
  66. }
  67. }
  68. for (int i = 0; i < m; i++)
  69. {
  70. temp = L[i][n_of_min];
  71. L[i][n_of_min] = L[i][j];
  72. L[i][j] = temp;
  73. }
  74. }
  75.  
  76. cout << "\nОтсортированная матрица:\n";
  77. for (int i = 0; i < m; i++) {
  78. for (int j = 0; j < n; j++) {
  79. cout << L[i][j] << "\t";
  80. }
  81. cout << "\n";
  82. }
  83. }
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement