Saturday, 2 February 2013

Transpose a Matrix using C program

Transpose a Matrix using C Program


#include<stdio.h>
#include<conio.h>
void main()
{
 int i,j, a[10][10],b[10][10],m,n;
 clrscr();
 printf("Enter Matrix Order I and J:");
 scanf("%d%d",&m,&n);
 printf("Enter Matrix A:\n");
 for(i=0; i<m; i++){
    for(j=0; j<n; j++){
    scanf("%d",&a[i][j]);
    }
 }
 for(i=0; i<m; i++){
    for(j=0; j<n; j++){
    b[i][j]=a[j][i];
    }
 }
 printf("\nTranspose of Matrix A is:\n");
 for(i=0; i<m; i++){
    for(j=0; j<n; j++){
     printf("%d   ",b[i][j]);
    }
    printf("\n");
 }
 getch();
}

Output:
Enter Matrix Order I & J:3 3
Enter Matrix A:
1   2   3
4   5   6
7   8   9

Transpose of Matrix A is:

1   4   7
2   5   8
3   6   9

Thanks...Comment it...

2 comments:

  1. Appreciation for nice Updates, I found something new and folks can get useful info about BEST ONLINE TRAINING

    ReplyDelete