Find the transpose of a matrix using C

  

Hey guys once again welcome to the Decoders blog, I hope you all are doing well and today I'm present with another logic but this time with something different it is a C logic which will help us to get the multiplication of given two matrices using arrays in C 

Here's the code which you can go through...........

//Transpose of a matrix
#include<stdio.h>
int main()
{
    int a[3][3],b[3][3],c[3][3];
    int i,j,k;
    printf("Enter the value of the matrix a:\n");
    //Storing the values for the matrix [A]
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            scanf("%d",&a[i][j]);
        }
    }

    //Displaying the matrix [A]
    printf("Matrix A:\n");
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            printf("%d\t",a[i][j]);
        }
        printf("\n");
    }

    //Logic for storing the values of the matrix [C]
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            for(k=0;k<3;k++)
            {
                c[i][k] = a[k][i];
            }
        }
    }

    //Displaying the values of the matrix [C]
    printf("Matrix C:\n");
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            printf("%d\t",c[i][j]);
        }
        printf("\n");
    }
    return(0);
}

Comments

Popular Posts