Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void lineSwap(int arr[][3], int dim1, int dim2, int line1, int line2);
- int main() {
- int mas[3][3] = { {10, 2, 9}, {2, 3, 1}, {6, 2, 5} };
- lineSwap(mas, 3, 3, 0, 2);
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) printf("%d ", mas[i][j]);
- printf("\n");
- }
- printf("\n");
- for (int a = 0; a < 2; a++) {
- for (int i = 0; i < 2; i++) {
- int s1 = 0, s2 = 0;
- for (int j = 0; j < 3; j++) {
- s1 += mas[i][j];
- s2 += mas[i + 1][j];
- }
- if (s1 > s2) lineSwap(mas, 3, 3, i, i + 1);
- }
- }
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) printf("%d ", mas[i][j]);
- printf("\n");
- }
- return 0;
- }
- void lineSwap(int arr[][3], int dim1, int dim2, int line1, int line2) {
- for (int i = 0; i < dim2; i++) {
- int tmp = arr[line1][i];
- arr[line1][i] = arr[line2][i];
- arr[line2][i] = tmp;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement