Wednesday, May 20, 2020

Transpose of matrix in C


  • Program :

#include <stdio.h>
int main()
{
    int a[10][10], transpose[10][10], r, c, i, j;
    printf("\n----------------TRANSPOSE OF MATRIX----------------"); 
    printf("\nEnter rows and columns: ");
    scanf("%d %d", &r, &c);

   
    printf("\nEnter matrix elements");
    for (i = 0; i < r; ++i)
        for (j = 0; j < c; ++j) {
            printf("\nEnter element A %d%d: ", i + 1, j + 1);
            scanf("%d", &a[i][j]);
        }

 
    printf("\nEntered matrix: \n");
    for (i = 0; i < r; ++i)
        for (j = 0; j < c; ++j) {
            printf("%d  ", a[i][j]);
            if (j == c - 1)
                printf("\n");
        }

 
    for (i = 0; i < r; ++i)
        for (j = 0; j < c; ++j) {
            transpose[j][i] = a[i][j];
        }

   
    printf("\nTranspose of the matrix:\n");
    for (i = 0; i < c; ++i)
        for (j = 0; j < r; ++j) {
            printf("%d  ", transpose[i][j]);
            if (j == r - 1)
                printf("\n");
        }
    return 0;
}




  • Output :


No comments:

Post a Comment

Function Overloading in C++

https://monitechvenkat1620.blogspot.com Program : #include <iostream> using namespace std; int c(int x, int y) {   return...