Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. void main()
  6. {
  7. setlocale(LC_ALL, "rus");
  8. int n = 4, **a, *summ;
  9. int buf;
  10. a = new int*[n];
  11. summ = new int[n];
  12. for (int i = 0; i < n; i++)
  13. {
  14. cout << endl;
  15. a[i] = new int[n];
  16. for (int j = 0; j < n; j++)
  17. {
  18. a[i][j] = rand() % 10 - 5;
  19. cout << a[i][j] << " ";
  20. }
  21. }
  22. for (int i = 0; i < n; i++)
  23. {
  24. summ[i] = 0;
  25. for (int j = 0; j < n; j++)
  26. {
  27. if (a[i][j] < 0) {
  28. summ[i] += a[i][j];
  29. }
  30. }
  31. }
  32. for (int i = 0; i < n; i++)
  33. {
  34. cout << endl;
  35. cout << "Сумма элементов в " << i + 1 << "-ой строке " << summ[i];
  36. }
  37. cout << endl;
  38. for (int i = 0; i < n - 1; i++)
  39. {
  40. for (int k = i + 1; k < n; k++)
  41. {
  42. if (summ[i] > summ[k])
  43. {
  44. buf = summ[i];
  45. summ[i] = summ[k];
  46. summ[k] = buf;
  47. for (int j = 0; j < n; j++)
  48. {
  49. buf = a[i][j];
  50. a[i][j] = a[i][k];
  51. a[i][k] = buf;
  52. }
  53. }
  54. }
  55. }
  56. for (int i = 0; i < n; i++)
  57. {
  58. cout << endl;
  59. for (int j = 0; j < n; j++)
  60. {
  61. cout << a[i][j] << " ";
  62. }
  63. }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement