We are hiring content writers to work from home

Resources » Articles/Knowledge Sharing » Computer & Technology

# C program of matrix addition,substraction,and multiplication

 Posted Date: 15-Mar-2008 Last Updated: 15-Mar-2008 Category: Computer & Technology Author: ashish singh Member Level: Gold Points: 5

/* Program of addition,substraction,and multiplication of matrix */

#include
#include
{
int i,j;
for(i=0;i {
for(j=0;j {
printf("\n Enter element :");
scanf("%d",&a[i][j]);
}
}
void print_mat(int m,int n,int a[5][5])
{
int i,j;
for(i=0;i {
for(j=0;jprintf(" %d",a[i][j]);
printf("\n");
}
}
void add_mat(int m,int n,int a[5][5],int b[5][5],int s[5][5])
{
int i,j;
for(i=0;i {
for(j=0;j {
s[i][j]=a[i][j]+b[i][j];
}
}
}
void sub_mat(int m,int n,int a[5][5],int b[5][5],int sd[5][5])
{
int i,j;
for(i=0;i {
for(j=0;j {
sd[i][j]=a[i][j]-b[i][j];
}
}
}
void mul_mat(int m,int n,int q,int a[5][5],int b[5][5],int mt[5][5])
{
int i,j,k;
for(i=0;i {
for(j=0;j {
mt[i][j]=0;
for(k=0;k {
mt[i][j]=mt[i][j]+a[i][k]*b[k][j];
}
}
}
}
void main()
{
int m,n,p,q,i,j,a[5][5],b[5][5],s[5][5],sd[5][5],mt[5][5];
printf("\n Enter order of first matrix :");
scanf("%d%d",&m,&n);
printf("\n Order of second matrix :");
scanf("%d%d",&p,&q);
if((m!=p)&&(n!=q))
printf("\n Matrices are imcompatable for addotion and substraction");
else
{
printf("\n Read the element of first matrix ");
printf("\n Read the element of second matrix ");
printf("\n FIRST MATRIX IS ......\n");
print_mat(m,n,a);
printf("\n SECOND MATRIX IS ....\n");
print_mat(p,q,b);
printf("\n AFTER ADDITION MATRIX IS ....\n");
print_mat(m,n,s);
sub_mat(m,n,a,b,sd);
printf("\n AFTER SUBSTRACTION MATRIX IS ....\n");
print_mat(m,n,sd);
}
if(p==q)
{
mul_mat(m,n,q,a,b,mt);
printf("\n AFTER MULTIPLICATION MATRIX IS ....\n");
print_mat(m,q,mt);
}
else
printf("\n Matrices are incompatible for multiplication ");
getch();
}

Did you like this resource? Share it with your friends and show your love!

Responses to "C program of matrix addition,substraction,and multiplication"
Guest Author: S Nair     08 Mar 2013
C programme to find the addition, subtraction and multiplication of matrices is very informative, helpful article and nice site. Thanks

Feedbacks

## Post Comment:

• Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
• No HTML formatting and links to other web sites are allowed.
• This is a strictly moderated site. Absolutely no spam allowed.
•  Name: Sign In to fill automatically. Email: (Will not be published, but required to validate comment) Type the numbers and letters shown on the left.

 Next Resource: C program the value of x^y using recursion Previous Resource: C Program to print reverse string by using stack Return to Resources Post New Resource Category: Computer & Technology

Post resources and earn money!

More Resources
 Popular Tags Tag posting guidelines Search Tags

### Subscribe to Email

• Get Jobs by Email
• Forum posts by Email
• Articles by Email