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 void main () in c?
How do I read the arrow keys? What about function keys?
What is bubble sort in c?
Is using exit() the same as using return?
Why we write conio h in c?
what is the differnce between programing langauge and tool? is sas is a programing langauge r tool?
Is malloc memset faster than calloc?
How important is structure in life?
why return type of main is not necessary in linux
State two uses of pointers in C?
Want to know how to write a C program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.
What was noalias and what ever happened to it?
Give a one-line C expression to test whether a number is a power of 2. [No loops allowed - it's a simple test.]
Do pointers need to be initialized?
What is pass by value in c?