SHARE
    TWEET
    Lavig

    Лабораторна робота No12 (Завдання 1)

    Nov 21st, 2024
    198
    0
    Never
    Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
    C++ 3.18 KB | None | 0 0
    1. #include <iostream>
    2. #include <windows.h>
    3. #include <format>
    4. using namespace std;
    5. int main()
    6. {
    7. SetConsoleOutputCP(1251);
    8. int const a{ 5 };
    9. int const b{ 6 };
    10. int i{}, j{};
    11. double arithmetic_mean1{}, arithmetic_mean2{}, arithmetic_mean3{}, arithmetic_mean4{}, arithmetic_mean5{}, arithmetic_mean6{}, max1{}, max2{}, max3{}, max4{}, max5{}, min1{}, min2{}, min3{}, min4{}, min5{}, sum1{}, sum2{}, sum3{}, sum4{}, sum5{}, sum6{};
    12. double Z[a][b]{};
    13. srand(time(0));
    14. cout << "Задана матриця: " << endl;
    15. for (i = 0; i < a; i++) {
    16. for (j = 0; j < b; j++) {
    17. Z[i][j] = rand() % 100;
    18. cout << format("{:7}", Z[i][j]);
    19. }
    20. cout << endl;
    21. }
    22. max1 = Z[0][0];
    23. max2 = Z[1][0];
    24. max3 = Z[2][0];
    25. max4 = Z[3][0];
    26. max5 = Z[4][0];
    27. min1 = Z[0][0];
    28. min2 = Z[1][0];
    29. min3 = Z[2][0];
    30. min4 = Z[3][0];
    31. min5 = Z[4][0];
    32. for (i = 0; i < a; i++) {
    33. for (j = 0; j < b; j++) {
    34. if (i == 0) {
    35. if (Z[i][j] > max1) {
    36. max1 = Z[i][j];
    37. }
    38. if (Z[i][j] < min1) {
    39. min1 = Z[i][j];
    40. }
    41. }
    42. if (i == 1) {
    43. if (Z[i][j] > max2) {
    44. max2 = Z[i][j];
    45. }
    46. if (Z[i][j] < min2) {
    47. min2 = Z[i][j];
    48. }
    49. }
    50. if (i == 2) {
    51. if (Z[i][j] > max3) {
    52. max3 = Z[i][j];
    53. }
    54. if (Z[i][j] < min3) {
    55. min3 = Z[i][j];
    56. }
    57. }
    58. if (i == 3) {
    59. if (Z[i][j] > max4) {
    60. max4 = Z[i][j];
    61. }
    62. if (Z[i][j] < min4) {
    63. min4 = Z[i][j];
    64. }
    65. }
    66. if (i == 4) {
    67. if (Z[i][j] > max5) {
    68. max5 = Z[i][j];
    69. }
    70. if (Z[i][j] < min5) {
    71. min5 = Z[i][j];
    72. }
    73. }
    74. if (j == 0) {
    75. sum1 += Z[i][j];
    76. }
    77. if (j == 1) {
    78. sum2 += Z[i][j];
    79. }
    80. if (j == 2) {
    81. sum3 += Z[i][j];
    82. }
    83. if (j == 3) {
    84. sum4 += Z[i][j];
    85. }
    86. if (j == 4) {
    87. sum5 += Z[i][j];
    88. }
    89. if (j == 5) {
    90. sum6 += Z[i][j];
    91. }
    92. }
    93. }
    94. arithmetic_mean1 = sum1 / 5;
    95. arithmetic_mean2 = sum2 / 5;
    96. arithmetic_mean3 = sum3 / 5;
    97. arithmetic_mean4 = sum4 / 5;
    98. arithmetic_mean5 = sum5 / 5;
    99. arithmetic_mean6 = sum6 / 5;
    100. cout << "Максимальний елемент першого рядка - " << max1 << endl;
    101. cout << "Максимальний елемент другого рядка - " << max2 << endl;
    102. cout << "Максимальний елемент третього рядка - " << max3 << endl;
    103. cout << "Максимальний елемент четвертого рядка - " << max4 << endl;
    104. cout << "Максимальний елемент п'ятого рядка - " << max5 << endl;
    105. cout << "Середнє арифметичне першого стовпця - " << arithmetic_mean1 << endl;
    106. cout << "Середнє арифметичне другого стовпця - " << arithmetic_mean2 << endl;
    107. cout << "Середнє арифметичне третього стовпця - " << arithmetic_mean3 << endl;
    108. cout << "Середнє арифметичне четвертого стовпця - " << arithmetic_mean4 << endl;
    109. cout << "Середнє арифметичне п'ятого стовпця - " << arithmetic_mean5 << endl;
    110. cout << "Середнє арифметичне шостого стовпця - " << arithmetic_mean6 << endl;
    111. }
    Advertisement
    Add Comment
    Please, Sign In to add comment
    Public Pastes
    We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
    Not a member of Pastebin yet?
    Sign Up, it unlocks many cool features!

    AltStyle によって変換されたページ (->オリジナル) /