+ 1

Why the below C code is not running properly?

//Matrix multiplication #include <stdio.h> #include <conio.h> int main() { int a[10][10],B[10][10],C[10][10],i,j,k,sum,m,n,p,q; sum=0; //clrscr(); printf("enter the size of matrix (row*column) A\n"); scanf("%d%d",&m,&n); printf("enter the size of matrix (row*column) B\n"); scanf("%d%d",&p,&q); if(n!=p) { printf("\nmultiplication is not possible"); } else { printf("\nenter elements for matrix A:\n"); for(i=0;i<m;i++); { for(j=0;j<n;j++); { printf("\nelement A[%d][%d]=",i,j); scanf("%d",&a[i][j]); } } printf("\nenter elements for matrix B:\n"); for(i=0;i<p;i++); { for(j=0;j<q;j++); { printf("\nelement B[%d][%d]=",i+1,j+1); scanf("%d",&B[i][j]); } } //now multiplication for(i=0;i<m;i++); { for(j=0;j<q;j++); { sum=0; for(k=0;k<p;k++) { sum=sum+a[i][k]*B[k][j]; C[i][j]=sum; } } } //printing result for(i=0;i<m;i++); { for(j=0;j<q;j++); { printf("%d\t",C[i][j]); } printf("\n"); } return 0; }}

12th Apr 2021, 12:31 PM
Coding San
Coding San - avatar
4 Answers
+ 10
Almost all of your *for* loops are doing nothing as you have terminated them with a semicolon . Also <conio.h> is a non standard header and is not supported by most of the modern standard compilers.
12th Apr 2021, 12:39 PM
Arsenic
Arsenic - avatar
+ 1
Arsenic 👍
12th Apr 2021, 2:11 PM
Jamal Saied
Jamal Saied - avatar
+ 1
Check the syntax
14th Apr 2021, 2:05 AM
Abdullah Mazeer
Abdullah Mazeer - avatar
+ 1
Do not use semicolon after for loop.
14th Apr 2021, 12:05 PM
Ambuj kumar