Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <ctime>
  4. #include <algorithm>
  5. using namespace std;
  6. int main()
  7. {
  8. srand(time(NULL));
  9. setlocale(LC_ALL, "rus");
  10. int n;
  11. int max1 = 0;
  12. int max2 = 0;
  13. int max3 = 0;
  14. int a[100][100];
  15. cout << "Введите порядок матрицы n: ";
  16. cin >> n;
  17. cout << "Исходная матрица A" << endl;
  18. for (int i = 0; i < n; i++)
  19. {
  20. for (int j = 0; j < n; j++)
  21. {
  22. a[i][j] = rand() % 30 + 1;
  23. cout << setw(4) << a[i][j];
  24. }
  25. cout << "\n";
  26. }
  27. cout << "Итоговая матрица Б:" << endl;
  28. for (int k=1;k<n)
  29. for (int i = 0; i < n; i++)
  30. {
  31. for (int j = 0; j < n; j += n - 1)
  32. {
  33. if (a[i][j] > max1)
  34. {
  35. max1 = a[i][j];
  36. }
  37. }
  38.  
  39. for (int j = 0; j < n; j++)
  40. {
  41. for (int i = 0; i < n; i += n - 1)
  42. {
  43. if (a[i][j] > max2)
  44. {
  45. max2 = a[i][j];
  46. }
  47. }
  48. }
  49. }
  50. max3 = max(max1, max2);
  51. for (int i = 0; i < (n + 1) / 2; i++)
  52. {
  53. for (int j = i; j < n; j++)
  54. {
  55. a[i][j] = max3;
  56. cout <<setw(4)<< a[i][i];
  57. }
  58. cout << "\n";
  59. }
  60. system("pause");
  61. return 0;
  62. }
  63.  
  64.  
  65.  
  66.  
  67.  
  68. //for (int k = 0; k < n; k++)
  69. //{
  70. // for (int i = 0; i < n; i++)
  71. // {
  72. // for (int j = 0; j < n; j += n - 1)
  73. // {
  74. // if (a[i][j] > max1)
  75. // {
  76. // max1 = a[i][j];
  77. // }
  78. // }
  79. // }
  80. // for (int j = 0; j < n; j++)
  81. // {
  82. // for (int i = 0; i < n; i += n - 1)
  83. // {
  84. // if (a[i][j] > max2)
  85. // {
  86. // max2 = a[i][j];
  87. // }
  88. // }
  89. // }
  90. // max3 = max(max1, max2);
  91. // cout << max3;
  92. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement