write a program in c language for the multiplication of two
matrices using pointers?

Answer Posted / rohan

#include<stdio.h>
#define row 3
#define col 3
#define col2 3
int main()
{
int a[row][col],b[col][col2],c[row][col2],i,j,k;
printf("Enter the element of first matrix:->\n");
for(i=1;i<=row;i++)
{
for(j=1;j<=col;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter the element of second matrix:->\n");
for(i=1;i<=col;i++)
{
for(j=1;j<=col2;j++)
{
scanf("%d",&b[i][j]);
}
}
/*printing of matrices*/
printf("\nMATRIX A\n");
for(i=1;i<=row;i++)
{
printf("\n");
for(j=1;j<=col;j++)
printf("%4d",a[i][j]);
}
printf("\nMATRIX B\n");
for(i=1;i<=col;i++)
{
printf("\n");
for(j=1;j<=col2;j++)
printf("%4d",b[i][j]);
}
/*multiplication*/
printf("\n\n");
for(i=1;i<=row;i++)
{
for(j=1;j<=col2;j++)
{
c[i][j]=0;
for(k=1;k<=col;k++)
c[i][j]=(c[i][j])+(a[i][k])*(b[k][j]);
}

}
/*printig of multiplication result*/
printf("MULTIPLICATION OF MATRIX A AND MATRIX B");
for(i=1;i<=row;i++)
{
printf("\n");
for(j=1;j<=col2;j++)
{
printf("%4d",c[i][j]);
}
}
printf("\n\n");
return 0;
}

Is This Answer Correct ?    7 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is int a keyword in c?

736


Explain what is the heap?

814


formula to convert 2500mmh2o into m3/hr

758


Why do we use pointer to pointer in c?

814


Write a program, where i have a grid with many cells, how many paths are possible from one point to other desired points.

972


.find the output of the following program? char*myfunc(char*ptr) { ptr +=3; return (ptr); } int main() { char*x,*y; x="HELLO"; y=myfunc(x); printf("y = %s ",y); return 0; }

2317


What is the difference between class and object in c?

827


What is the difference between functions getch() and getche()?

833


Define the scope of static variables.

836


why we wont use '&' sing in aceesing the string using scanf

2080


The process of repeatedly running a set of computer instructions until some condition is specifed a) condition b) sequential condition c) global d) iteration

850


Is there sort function in c?

791


Can i use “int” data type to store the value 32768? Why?

971


An organised method of depicting the use of an area of computer memory used to signify the uses for different parts of the memory a) swap b) extended memory c) memory map d) all of the above

932


What is indirection? How many levels of pointers can you have?

912