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
How many header files are in c?
Is exit(status) truly equivalent to returning the same status from main?
What is this infamous null pointer, anyway?
What is the use of define in c?
Why we use stdio h in c?
FORMATTED INPUT/OUTPUT functions are a) scanf() and printf() b) gets() and puts() c) getchar() and putchar() d) all the above
what are bit fields in c?
Is c procedural or functional?
What is d'n in c?
How can I trap or ignore keyboard interrupts like control-c?
What are the 3 types of structures?
What is merge sort in c?
What is the purpose of main() function?
Is anything faster than c?
Write a program to produce the following output: 1 2 3 4 5 6 7 8 9 10