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

How many header files are in c?

799


Is exit(status) truly equivalent to returning the same status from main?

860


What is this infamous null pointer, anyway?

825


What is the use of define in c?

835


Why we use stdio h in c?

820


FORMATTED INPUT/OUTPUT functions are a) scanf() and printf() b) gets() and puts() c) getchar() and putchar() d) all the above

912


what are bit fields in c?

1258


Is c procedural or functional?

815


What is d'n in c?

855


How can I trap or ignore keyboard interrupts like control-c?

859


What are the 3 types of structures?

809


What is merge sort in c?

859


What is the purpose of main() function?

973


Is anything faster than c?

811


Write a program to produce the following output: 1 2 3 4 5 6 7 8 9 10

15478