Advertisement
thevals

lab2t2

Oct 28th, 2021
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 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.     for (int a = 0; a < 2; a++) {
  13.         for (int i = 0; i < 2; i++) {
  14.             int s1 = 0, s2 = 0;
  15.             for (int j = 0; j < 3; j++) {
  16.                 s1 += mas[i][j];
  17.                 s2 += mas[i + 1][j];
  18.             }
  19.             if (s1 > s2) lineSwap(mas, 3, 3, i, i + 1);
  20.         }
  21.     }
  22.     for (int i = 0; i < 3; i++) {
  23.         for (int j = 0; j < 3; j++) printf("%d ", mas[i][j]);
  24.         printf("\n");
  25.     }
  26.     return 0;
  27. }
  28. void  lineSwap(int arr[][3], int dim1, int dim2, int line1, int line2) {
  29.     for (int i = 0; i < dim2; i++) {
  30.         int tmp = arr[line1][i];
  31.         arr[line1][i] = arr[line2][i];
  32.         arr[line2][i] = tmp;
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement