#include <stdio.h>
#include <stdlib.h>
#include <time.h>
// Поменять строки в массиве, массив одномерный, интерпретировать его нужно как двумерный
// Номера строк для обмена вводит пользователь
void FillArr( int arr[], const int n ) { // int a[] == int* a
int i;
for( i = 0; i < n; ++i )
arr[ i ] = rand() % 101 - 50;
}
void PrintArr( const int a[], const int rows, const int cols ) {
int i, j;
for( i = 0; i < rows; ++i ) {
for( j = 0; j < cols; ++j )
printf( "%5d", a[ i * cols + j ] );
puts("");
}
}
int main() {
srand(time(0));
const int rows = 3, cols = 4;
int arr[ rows * cols ];
int j;
FillArr(arr, rows*cols);
PrintArr(arr, rows, cols);
int a, b;
printf("Enter two lines (from 0 to 4) that need to swap in array\n");
scanf( "%d%d", &a, &b );
printf("\n");
printf(" %d\t%d", a, b);
// Swap colms in array
int i, tmp;
for( i = 0; i < rows*cols; ++i ) {
tmp = arr[a*i];
arr[a*i] = arr[b*i + rows];
arr[b*i + rows] = tmp;
//printf( "%5d", arr[ i * cols ] );
puts("");
}
PrintArr(arr, rows, cols);
printf("\n");
printf("\nHello world!\n");
return 0;
}