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;
}
Learn More :
Matrix
- C Program To Find Transpose Of A Matrix
- C Program To Multiply Two Matrices
- C Program To Print Tridiagonal Matrix
- C Program To Understand Use Of Pointers In MATRIX
- C Program : 4x4 Matrix Keypad connected to Arduino. This code prints the key pressed on the keypad to the serial port.
- matrix sort in C Program
- Sequential Matrix Multiplication C Program
- C Program to calculate sum of two m*n matrices & store the result in 3 matrix
- C Program to accept m*n matrix from user and display the elements of given matrix using function
- C Program to calculate the sum of elements of upper triangle of a n*n matrix using DMA
- C program to display the transpose of given 3 X 3 matrix
- Calculate sum of element of upper triangle of m*n matrix by using dynamic memory allocation
- Calculate sum of non-diagonal element in m*n matrix C Program
- Calculate sum of element of lower triangle of m*n matrix by using dynamic memory allocation
- C Program Shortest Distance in Matrix
- C Program To Read The Adjecancy Matrix of Directed Graph And Convert It Into Adjecancy List
Swap
- C Program to Calculate Grid Size, Initialized Number onto tile, Initialize Tile Loop and If Grid is Even, Swap The Tiles Numbered 1 and 2
- C Program To Swap Two Numbers Without Using Third Variable
- C Program to Swap two variables without using third variable ?
- C Program To Swap two Numbers Using Pointers
- C Program To Swap Two numbers Without Third Variable
- C Program Swapping numbers using call by reference
- C Function to xorSwap and addSwap in C Programming
- C Program to swap the values of two variables by using call by reference