Advertisement
thevals

laba2

Oct 28th, 2021
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 KB | None | 0 0
  1. #include <stdio.h>
  2. void  lineSwap(int arr[][3], int dim1, int dim2, int line1, int line2);
  3.  
  4. int main() {
  5.     int mas[3][3] = { {10, 2, 9}, {2, 3, 1}, {6, 2, 5} };
  6.     lineSwap(mas, 3, 3, 0, 2);
  7.     for (int i = 0; i < 3; i++) {
  8.         for (int j = 0; j < 3; j++) printf("%d ", mas[i][j]);
  9.         printf("\n");
  10.     }
  11.     printf("\n");
  12.  
  13.     for (int a = 2; a > 0; a--) {
  14.         int s1 = 0, s2 = 0;
  15.         for (int i = 0; i < a; i++, s2 = 0) {
  16.             for (int j = 0; j < 3; j++) {
  17.                 if(i== 0) s1 += mas[i][j];
  18.                 s2 += mas[i + 1][j];
  19.             }
  20.             if (s1 > s2) {
  21.                 lineSwap(mas, 3, 3, i, i + 1);
  22.             }
  23.         }
  24.     }
  25.    
  26.     for (int i = 0; i < 3; i++) {
  27.         for (int j = 0; j < 3; j++) printf("%d ", mas[i][j]);
  28.         printf("\n");
  29.     }
  30.     return 0;
  31. }
  32. void  lineSwap(int arr[][3], int dim1, int dim2, int line1, int line2) {
  33.     for (int i = 0; i < dim2; i++) {
  34.         int tmp = arr[line1][i];
  35.         arr[line1][i] = arr[line2][i];
  36.         arr[line2][i] = tmp;
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement