C Matrix addition program

#include<stdio.h>
int main(){
int m,n,p,q,r,d,k,sum=0;
int a[10][10],b[10][10],c[10][10];
printf(“Enter Rows and Columns of the Matrices”);
scanf("%d%d",&m,&n);
printf(“Enter Elements of the first matrices”);
for(r=0;r<m;r++){
for(d=0;d<n;d++){
scanf("%d",a[r][d]);}}
printf(“Enter Rows and Columns of Second Matrices”);
scanf("%d%d",&p,&q);
if(n!=p){
printf(“Matrices multiplication is not possible because n is not equal to p”);
}
else{
printf(“Enter the element of second matrices”);
for(r=0;r<p;r++)
for(d=0;d<q;d++)
scanf("%d",&b[r][d]);
for(r=0;r<m;r++)
for(d=0;d<q;d++)
for(k=0;k<p;k++){
sum=sum+a[r][k]*b[k][d];
}
c[r][d]=sum;
sum=0;
}
printf(“Product of two matrices is:”);
for(r=0;r<m;r++)
for(d=0;d<q;d++)
printf("%d\t",c[r][d]);
printf("\n");
return 0;
}

In this its not running having some issue can anyone please help to check that whats the problem Its compiled run but give runtime error after taking first matrices row and column only take 2 element and do exit

this shoud be “scanf(”%d",&a[r][d]);}}", you forgot ‘&’ here :slightly_smiling_face:

1 Like