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

Answer Posted / shankey narang

// write a program to multipication of a matrix
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
void main()
{
int *ptr1,*ptr2,*ptr3;
int m,n,i,j,k;
printf("enter m & n=");
scanf("%d%d",&m,&n);
ptr1=(int*)malloc((m*n)*sizeof(int));
ptr2=(int*)malloc((m*n)*sizeof(int));
ptr3=(int*)malloc((m*n)*sizeof(int));
printf("enter elements of 1st matrix=");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",((ptr1+i)+j)) ;
}
}
printf("enter elements of 2nd matrix=");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",((ptr2+i)+j)) ;
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
*((ptr3+i)+j)=0;
for(k=0;k<n;k++)
{
*((ptr3+i)+j)=*((ptr3+i)+j)+(*((ptr1+i)+j))*(*((ptr2+j)+k));
}
}
}
printf("multipication is=\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("%d\t",*((ptr3+i)+j)) ;
}
printf("\n");
}
getch();
}

Is This Answer Correct ?    13 Yes 21 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which one would you prefer - a macro or a function?

594


what do you mean by inline function in C?

605


What are the types of bitwise operator?

657


Draw a flowchart to produce a printed list of all the students over the age of 20 in a class .The input records contains the name and age of students. Assume a sentinel value of 99 for the age field of the trailer record

4736


Can the sizeof operator be used to tell the size of an array passed to a function?

609






What is the use of function overloading in C?

670


What does sizeof return c?

594


main use of recursive function a) processing speed high b) reduce program length/reduce repeated statements c) if you do not, use iterative methods like, for, while or do-while d) all the above

608


In c programming, explain how do you insert quote characters (? And ?) Into the output screen?

756


What do you mean by command line argument?

634


What is hashing in c?

638


writ a program to compare using strcmp VIVA and viva with its output.

1513


What is malloc and calloc?

567


What is structure in c language?

610


int far *near * p; means

3109