Advertisement
Courbe_Impliquee

Двойной массив1

Dec 22nd, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <clocale>
  4. using namespace std;
  5. int main()
  6. {
  7. setlocale(LC_ALL, "rus");
  8. int n, m, k, t, sum = 0,min=0,p;
  9. cout << "Введите кол-во строк и столбцов матрицы: ";
  10. cin >> n >> m;
  11. cout << endl;
  12. int** arr = new int *[n];
  13. for (int i = 0; i < n; ++i)
  14. arr[i] = new int[m];
  15. int*brr = new int[n];
  16. cout << "Введите элементы матрицы:" << endl;
  17. for (int i = 0; i < n; i++) {
  18. for (int j = 0; j < m; j++) {
  19. cin >> arr[i][j];
  20. }
  21. }
  22. cout << endl;
  23. t = m;
  24. for (int j = 0; j < m; j++) {
  25. for (int i = 0; i < n; i++) {
  26. if (arr[i][j] == 0) {
  27. t--;
  28. break;
  29. }
  30. }
  31. }
  32. for (int i = 0; i < n; i++) {
  33. brr[i] = 0;
  34. for (int j = 0; j < m; j++) {
  35. cout << arr[i][j] << " ";
  36. if (arr[i][j] > 0 && (arr[i][j]) % 2 == 0)
  37. brr[i] += arr[i][j];
  38. }
  39. cout << "|" << brr[i]<<endl;
  40. }
  41. cout << endl;
  42. for (int i = 0; i < n; i++) {
  43. min = i;
  44. for (int j = i + 1; j < n; j++) {
  45. if (brr[j] < brr[min]) {
  46. min = j;
  47. p = brr[i];
  48. brr[i] = brr[min];
  49. brr[min] = p;
  50. for (int j = 0; j < m; j++) {
  51. k = arr[i][j];
  52. arr[i][j] = arr[min][j];
  53. arr[min][j] = k;
  54. }
  55. }
  56. }
  57. }
  58. cout << "Кол-во столбцов без нулей: " << t << endl;
  59. cout << endl;
  60. cout << "Упорядоченный массив: " << endl;
  61. for (int i = 0; i < n; i++) {
  62. for (int j = 0; j < m; j++) {
  63. cout << arr[i][j] << " ";
  64. }
  65. cout << "|" << brr[i] << endl;
  66. }
  67. system("pause");
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement