write a program in c language for the multiplication of two
matrices using pointers?
Answer Posted / ruchi
#include<stdio.h>
#include<conio.h>
int main()
{
int n,m,i,j,k;
int a[38][38],b[38][38],p[38][38];
printf("\nEnter the number of rows and coloumns ");
scanf("%d %d",&n,&m);
printf("\nEnter the elements of first matrix ");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%d",(*(a+i)+j));
}
}
printf("\nMatrix is ");
for(i=0;i<n;i++)
{
printf("\n");
for(j=0;j<m;j++)
{
printf("%d",*(*(a+i)+j));
printf("\t");
}
}
printf("\nEnter the elements of second matrix ");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%d",(*(b+i)+j));
}
}
printf("\nMatrix is ");
for(i=0;i<n;i++)
{
printf("\n");
for(j=0;j<m;j++)
{
printf("%d",*(*(b+i)+j));
printf("\t");
}
}
printf("\nAfter multiplication ");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
p[i][j]=0;
for(k=0;k<n;k++)
{
p[i][j]+=a[i][k]*b[k][j];
}
}
}
for(i=0;i<n;i++)
{
printf("\n");
for(j=0;j<m;j++)
{
printf("%d",*(*(p+i)+j));
printf("\t");
}
}
getch();
}
Is This Answer Correct ? | 35 Yes | 14 No |
Post New Answer View All Answers
What is the use of typedef in structure in c?
Explain the difference between the local variable and global variable in c?
What is pivot in c?
What is self-referential structure in c programming?
Write a program to print ASCII code for a given digit.
Is main an identifier in c?
What are local static variables? How can you use them?
What are the two types of structure?
What is a pointer on a pointer in c programming language?
How can I read and write comma-delimited text?
Explain how do you search data in a data file using random access method?
Can we access the array using a pointer in c language?
What is a const pointer in c?
What is volatile variable in c with example?
Write a simple code fragment that will check if a number is positive or negative.