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