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

write a progrmm in c language take user interface generate table using for loop?

1826


How do you generate random numbers in C?

946


Q.1 write aprogram to stack using linklist o insert 40 items? Q.2 write a program to implement circular queue with help of linklist?

1838


How to declare a variable?

794


Why we use void main in c?

872


What are the types of arrays in c?

875


How can I use a preprocessorif expression to ?

805


How can I make sure that my program is the only one accessing a file?

980


What is the difference between class and object in c?

848


What is the difference between array and pointer in c?

832


Explain what is the purpose of "extern" keyword in a function declaration?

835


When a c file is executed there are many files that are automatically opened what are they files?

847


What is the purpose of main() function?

963


Is null valid for pointers to functions?

886


What is the process of writing the null pointer?

808