0

Here's my code:

#include<stdio.h> 
#include<conio.h> 
int main(void) 
{ 

int a[100][100]; /* initializing matrices to '0' */ 
int b[100][100]; 
int c[100][100]; /*matrix-c for multiplication*/ 

/*r1,c1 are rows and coloumns for matrix-a.r2,c2 for matrix-b.*/ 
int r1,c1,r2,c2; 
int i,j,k; 
clrscr(); 


printf("enter the no of ROWS and COLOUMNS for MATRIX-A\n"); 
scanf("%d %d",&r1,&c1); 
printf("enter the no of ROWS and COLOUMNS for MATRIX-B\n"); 
scanf("%d %d",&r2,&c2); 

if(c1==r2) 
{ 

printf("matrix multiplication possible\n\nenter numbers in MATRIX-A\n");


/* to enter numbers in matrix-a*/ 
for(i=0;i<r1;i++) 
for(j=0;j<c1;j++) 

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


printf("enter numbers in MATRIX-B\n");


/* to enter numbers in matrix-b*/


for(i=0;i<r2;i++)
for(j=0;j<c2;j++) 

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


/*for matrices multiplication*/ 
for(i=0;i<r1;i++) 
for(j=0;j<c2;j++) 
for(k=0;k<c1;k++) 
*(*(c+i)+j)+=*(*(a+i)+j)*(*(*(b+k)+j)); 


printf("result of multiplication of matrices is \n"); 
/*to display as matrix format*/ 
for(i=0;j<r1;i++) 
{ 
printf("\n"); 
for(j=0;j<c2;j++) 
printf("%d\t",*(*(c+i)+j)); 
} 


} //if 

else 
printf("MATRIX multiplication not Possible\n"); 
getch(); 
return 0; 
}

It runs but i dont get any output..:(

Edited by adityasingh95

2
Contributors
1
Reply
13
Views
4 Years
Discussion Span
Last Post by JasonHippy
0

OK, a couple of things:
Firstly you've posted in the wrong forum. This is C code, not C++! (Not the end of the world, but FYI!)
Secondly, well done for using the code tags feature (most noobs forget this), but please remember to correctly indent your code in future as it makes it a lot easier for other users to read and understand!

In relation to your actual problem, this line looks problematic:

/*to display as matrix format*/
for(i=0;j<r1;i++) 

If I'm not mistaken, the 'j' in the break condition of the for loop should be an 'i'.
So change it to:

/*to display as matrix format*/
for(i=0;i<r1;i++) 

And that should solve your problem! :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.