How to write a C Program to Swap Matrix in C Programming Language ?
Solution:
#include <stdio.h>
#include <stdlib.h>
#define MAX 100
int main()
{
int a[MAX][MAX],i,j,n,m,zbirG=0,zbirD=0,temp=0,d,g;
scanf ("%d%d",&n,&m);
for (i=0;i<n;i++){
for (j=0;j<m;j++)
scanf ("%d",&a[i][j]);
}
g=0; d=n-1;
while (g<=d){
for (j=0;j<m;j++){
zbirG+=a[g][j];
zbirD+=a[d][j]; }
if (zbirG>zbirG){
for (j=0;j<m;j++){
temp=a[g][j];
a[g][j]=a[d][j];
a[d][j]=temp; }
}
g++; d--;
zbirD=0; zbirG=0;
}
for (i=0;i<n;i++){
printf ("\n");
for (j=0;j<m;j++)
printf ("%d ",a[i][j]);
}
return 0;
}