write a program that swaps values between different locations in a two dimensional array. make sure that the locations between which the values are being exchanged are symmetric.
#include <stdio.h>
int main ()
{
int values[3][3];
int i,j;
for (i=0;i<3;i++)
{
for (j=0;j<3;j++)
{
printf("Enter values[%d][%d]: ",i,j);
scanf("%d",&values[i][j]);
}
}
printf("\nCurrent matrix:\n");
for(i=0;i<3;i++)
{
printf("\n");
for (j=0;j<3;j++)
{
printf("%d\t",values[i][j]);
}
}
for(i=0;i<3;i++)
{
int temp = values[i][0];
values[i][0] = values[i][2];
values[i][2] = temp;
}
printf("\n\n");
printf("\nMatrix after swapping \n");
for(i=0;i<3;i++)
{
printf("\n");
for (j=0;j<3;j++)
{
printf("%d\t",values[i][j]);
}
}
getchar();
getchar();
}
Comments
Leave a comment