Example:
Input
3 3
9 2 7
4 5 6
1 8 3
Output:
1 2 3
4 5 6
9 8 7
#include<stdio.h>#include <stdlib.h>int main(){int r,c;scanf("%d %d\n",&r,&c);int mat[r][c];for(int row=0;row<r;row++){ for(int col=0;col<c;col++) { scanf("%d ",&mat[row][col]); }}int sort[]={mat[0][0],mat[0][c-1],mat[r-1][c-1],mat[r-1][0]};for(int i=0;i<4;i++){ for(int j=i+1;j<4;j++) { if(sort[i]>sort[j]) { int temp=sort[i]; sort[i]=sort[j]; sort[j]=temp; } }}mat[0][0]=sort[0];mat[0][c-1]=sort[1];mat[r-1][c-1]=sort[2];mat[r-1][0]=sort[3];for(int row=0;row<r;row++){ for(int col=0;col<c;col++) { printf("%d ",mat[row][col]); } printf("\n");}}Example:
Input
4 5
80 50 45 86 20
48 57 10 44 30
22 47 58 44 27
74 36 84 40 99
Output:
80 50 20 86 45
48 57 30 44 10
22 47 27 44 58
74 36 99 40 84
#include<stdio.h>int main(){ int r,c; scanf("%d %d",&r,&c); int arr[r+1][c+1]; for(int row=1;row<=r;row++) for(int col=1;col<=c;col++) scanf("%d",&arr[row][col]); for(int row=1;row<=r;row++) { int k=0,ctr=c; for(int col=1;col<=c;col++) { if(k==0) printf("%d ",arr[row][col]); else printf("%d ",arr[row][ctr--]); if(c/col==2) k=1; } printf("\n"); }}