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


Please Help Members By Posting Answers For Below Questions

What is the use of typedef in structure in c?

536


Explain the difference between the local variable and global variable in c?

593


What is pivot in c?

563


What is self-referential structure in c programming?

653


Write a program to print ASCII code for a given digit.

679






Is main an identifier in c?

593


What are local static variables? How can you use them?

639


What are the two types of structure?

569


What is a pointer on a pointer in c programming language?

616


How can I read and write comma-delimited text?

616


Explain how do you search data in a data file using random access method?

691


Can we access the array using a pointer in c language?

556


What is a const pointer in c?

666


What is volatile variable in c with example?

581


Write a simple code fragment that will check if a number is positive or negative.

704