0% found this document useful (0 votes)
16 views

Message

The document contains code for string comparison, matrix addition, subtraction and multiplication. It takes in dimensions and elements of two matrices and performs the specified operation based on given operator, printing the result.

Uploaded by

Mansif Hossain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Message

The document contains code for string comparison, matrix addition, subtraction and multiplication. It takes in dimensions and elements of two matrices and performs the specified operation based on given operator, printing the result.

Uploaded by

Mansif Hossain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

#include<stdio.

h>

int scompare(char ara1[],char ara2[])


{
int i=0;
while(1)
{
if(ara1[i]=='\0' && ara2[i]=='\0')
{
return 0;
}

else if(ara1[i]=='\0')
{
return 3;
}

else if(ara2[i]=='\0')
{
return 2;
}

else if(ara1[i]>ara2[i])
{
return 2;
}

else if(ara1[i]<ara2[i])
{
return 3;
}

i++;
}}
int main()
{
int m,n,i,j;
scanf("%d %d",&m,&n);
int ara[m][n];
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
ara[i][j]=0;
}
}
int q;
scanf("%d",&q);
while(q--)
{

char str[100];
int x,y;
scanf("%s %d %d",str,&x,&y);
int ara2[x][y];
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
{
scanf("%d",&ara2[i][j]);
}
}
char a[4]={'A','D','D'};
char s[4]={'S','U','B'};
char ml[4]={'M','U','L'};

if(scompare(str,a)==0)
{
if(m==x && n==y)
{
int ara3[m][n];
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
ara3[i][j]=ara[i][j]+ara2[i][j];
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n-1;j++)
{
printf("%d ",ara3[i][j]);
}
printf("%d",ara3[i][n-1]);
printf("\n");
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
ara[i][j]=ara3[i][j];
}

}
}
else
printf("Invalid Operation!\n");

}
if(scompare(str,s)==0)

{
if(m==x && n==y)
{
int ara3[m][n];
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
ara3[i][j]=ara[i][j]-ara2[i][j];
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n-1;j++)
{
printf("%d ",ara3[i][j]);
}
printf("%d",ara3[i][n-1]);
printf("\n");
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
ara[i][j]=ara3[i][j];
}

}
}
else
printf("Invalid Operation!\n");
}
else if(scompare(str,ml)==0)
{
if(n==x)
{
int ara3[m][y];
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
long int multi=0;
for(int p=0;p<n;p++)
{
multi+=ara[i][p]*ara2[p][j];
}
ara3[i][j]=multi;
}
}

for(i=0;i<m;i++)
{
for(j=0;j<y-1;j++)
{
printf("%d ",ara3[i][j]);
}
printf("%d",ara3[i][y-1]);
printf("\n");}
n=m;
m=y;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
ara[i][j]=ara3[i][j];
}

}
}
else if(n!=x)
printf("Invalid Operation!\n");

}
return 0;
}

You might also like