Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <vector>
- #include <iostream>
- using namespace std;
- int main() {
- setlocale(LC_ALL, "rus");
- float** L;
- int m, n;
- float min, sum = 0, temp;
- int n_of_min, temp_n{};
- cout << "Введите количество строк(m) и количество столбцов(n) (1 < (m, n) < 10): ";
- while (!(cin >> m >> n) || (cin.peek() != '\n') || (m < 2 || m > 9) || (n < 2 || n > 9)) {
- cin.clear();
- while (cin.get() != '\n');
- cout << "Неверный ввод! m, n = ";
- }
- L = new float* [m];
- for (int i = 0; i < m; i++) {
- L[i] = new float[n];
- for (int k = 0; k < n; k++) {
- cout << "L[" << i + 1 << "][" << k + 1 << "] = ";
- while (!(cin >> L[i][k]) || (cin.peek() != '\n') || L[i][k] < -100 || L[i][k] > 100) {
- cin.clear();
- while (cin.get() != '\n');
- cout << "L[" << i + 1 << "][" << k + 1 << "] = ";
- }
- }
- }
- cout << "\nПолученная матрица:\n";
- for (int i = 0; i < m; i++) {
- for (int j = 0; j < n; j++) {
- cout << L[i][j] << "\t";
- }
- cout << "\n";
- }
- cout << "\nСтроки со элементами меньше нуля: ";
- for (int i = 0; i < m; i++) {
- for (int j = 0; j < n; j++) {
- if (L[i][j] < 0) {
- cout << i + 1 << " ";
- break;
- }
- }
- }
- for (int j = 0; j < n; j++) {
- min = -100, n_of_min = -1;
- for (int i = j; i < n; i++) {
- temp = 100;
- for (int k = 0; k < m; k++) {
- if (L[k][i] <= temp) {
- temp = L[k][i];
- temp_n = i;
- }
- }
- if (temp >= min) {
- min = temp;
- n_of_min = temp_n;
- }
- }
- for (int i = 0; i < m; i++)
- {
- temp = L[i][n_of_min];
- L[i][n_of_min] = L[i][j];
- L[i][j] = temp;
- }
- }
- cout << "\nОтсортированная матрица:\n";
- for (int i = 0; i < m; i++) {
- for (int j = 0; j < n; j++) {
- cout << L[i][j] << "\t";
- }
- cout << "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement