Tuesday, July 19, 2011

Program to find transpos of a matrix using function by passing matrix as parameter

/*Serial No.118     [swami95.cpp]*/

#include<stdio.h>
#include<conio.h>
void tran(int mat[10][10]);
int i,j,r,c;
void main()
{
int mat1[10][10];

clrscr();
printf("enter the no of rows=");
scanf("%d",&r);
printf("enter the no of column=");
scanf("%d",&c);
printf("enter the Ist matrix\n");
for(i=0;i<r;i++)
    {
    for(j=0;j<c;j++)
        {
        scanf("%d",&mat1[i][j]);
        }
    }
printf("\n\n\nFirst Entered matrix is:\n");
for(i=0;i<r;i++)
    {
    printf("\n");
    for(j=0;j<c;j++)
        {
        printf("\t%d",mat1[i][j]);
        }
    }
printf("\n\nTranspose of matrix is:\n");
tran(mat1);

getch();
}
void tran(int mat[10][10])
    {
    for(i=0;i<c;i++)
        {
        printf("\n");
        for(j=0;j<r;j++)
            {
            printf("\t%d",mat[j][i]);
            }
        }
    }

No comments:

Post a Comment

If you have any doubt, feel free to ask...