Answer to Question #198552 in C for zojee Arsal

Question #198552

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.


1
Expert's answer
2021-05-25T14:21:59-0400
#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]);
        }
    }
}

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