#include
#include
#include
#include void main()
{
int m1[30][30],m2[30][30],m3[30][30]={0};
int i,j,x,k,r1,r2,c1,c2,n,ch,sum=0;
char wish,y;
clrscr();
printf(“enter no of row for 1st matrix”);
scanf(“%d”,&r1);
printf(“enter no of col for 1st matrix”);
scanf(“%d”,&c1);
for(i=0;i<r1;i++)
for(j=0;j<c1;j++)
{
printf(“\n\t\t enter a[%d][%d]:”,i,j);
scanf(“%d”,&m1[i][j]);
}
printf(“enter no of row for 2nd matrix”);
scanf(“%d”,&r2);
printf(“enter no of col for 2nd matrix”);
scanf(“%d”,&c2);
for(i=0;i<r2;i++)
for(j=0;j<c2;j++)
{
printf(“\n\t\t enter a[%d][%d]:”,i,j);
scanf(“%d”,&m2[i][j]);
}
menu:
printf(“\n for sum of matrix press 1”);
printf(“\n for mutiplication of matrix press 2”);
printf(“\n for transpose of 1st matrix press 3”);
printf(“\n for cheaking symatericness of 1st matrix press 4”);
printf(“\n for cheaking sqew symatry matrix press 5\n”);
scanf(“%d”,&ch);
switch(ch)
{
case 1://addition
if((r1==r2)&&(c1==c2))
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
m3[i][j]=m1[i][j]+m2[i][j];
}
else
{
exit(0);
}
for(i=0;i<r1;i++)
{
printf(“\n”);
for(j=0;j<c1;j++)
printf(“\t\t%d”,m3[i][j]);
}
break;
case 2://multiplication
sum=0;
if(c1==r2)
{
for(i=0;i<r1;i++)
{
printf(“\n”);
for(j=0;j<c2;j++)
{
for(k=0;k<c1;k++)
{
sum+=(m1[i][k]*m2[k][j]);
}
printf(“\t\t%d”,sum);
sum=0;
}
}
}
else
exit(0);
break;
case 3:
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
m3[j][i]=m1[i][j] ;
}
}
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf(“\t\t%d”,m3[i][j]);
}
printf(“\n”);
}
break;
case 4:
/*int flag=0;
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
m3[j][i]=m1[i][j];
}
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
if(m3[i][j]==m1[i][j])
flag++;
}
}
if(flag==r1*c1)
printf(” 1st matrix is symatric”);
else
printf(” 1st matrix is not symatric”);*/
int flag=1;
for(i=0;i<r1;i++)
{
for(j=i+1;j<c1;j++)
{
if(m1[i][j]!=m1[j][i])
{
flag=0;
}
}
}
if(flag==1)
printf(” 1st matrix is symatric”);
else
printf(” 1st matrix is not symatric”);
break;
case 5://skew symatric
int fl=0;
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
m3[j][i]=m1[i][j];
}
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
if(m3[i][j]==-m1[i][j])
fl++;
}
}
if(fl==r1*c1)
printf(” 1st matrix is skew symatric”);
else
printf(” 1st matrix is not skew symatric”);
}
getch();
}//prg terminates
Leave a Reply