    0

# How do you write a C program for matrix addition and multiplication?

#include<stdio.h>

#include<conio.h>

main()

{ int a,b,c,m,n,i,j,p,q,op;

printf("enter the order of matrix a:n");

scanf("%d",&m,&n);

printf("enter the %d elements of a\n",m*);

for(i=0;i<m;i++)

for(j=0;j<n;j++)

scanf("%d",&a[i][j]);

printf("enter the order of matrix b:n");

scanf("%d",&p,&q);

printf("enter the %d elements of b\n",p*q);

for(i=0;i<p;i++)

for(j=0;j<q;j++)

scanf("%d",&b[i][j]);

printf("enter the option\n");

scanf("%d",&option);

switch(op)

{ case '+' : if(m==p&&n==q)

printf("the resultant matrix c is:\n");

for(i=0;i<m;i++)

for(j=0;j<n;j++)

c[i][j]=a[i][j]+b[i][j];

printf("%d",c[i][j]);

printf("\n");

break;

case '/' : if(n==p)

{ for(i=0;i<m;;i++);

{for(j=0;j<q;j++)

{printf("%d",c[i][j]);

}

}

c[i][j]=0;

for(p=0;p<n;p++)

c[i][j]=c[i][j]+a[i][p]*b[p][j]:

}

printf("resultant matrix is:\n");

for(i=0;i<m;;i++);

{for(j=0;j<q;j++)

{printf("%d\t",c[i][j]);

}

}

printf("\n");

getch();

} Study guides

1 card

## Data Science

➡️
See all cards
4.17
6 Reviews Earn +20 pts  