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
What is the use of c language in real life?
in multiple branching construct "default" case is a) optional b) compulsarily c) it is not include in this construct d) none of the above
What are the different types of C instructions?
What is #define in c?
Is malloc memset faster than calloc?
What is an expression?
pierrot's divisor program using c or c++ code
Is main is user defined function?
How can you increase the size of a statically allocated array?
please explain clearly about execution of c program in detail,in which stage are the printf sacnf getting into exeecutable code
what is a NULL Pointer? Whether it is same as an uninitialized pointer?
What is a rvalue?
What does the file stdio.h contain?
Do you know the purpose of 'register' keyword?
How does struct work in c?