Answer to Question #198558 in C for zojee Arsal

Question #198558

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.


1
Expert's answer
2021-05-27T06:24:51-0400
#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();
}







Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS