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

Write a program in c to replace any vowel in a string with z?

699


How can you determine the size of an allocated portion of memory?

748


How can I read data from data files with particular formats?

607


How can my program discover the complete pathname to the executable from which it was invoked?

665


Can you please explain the difference between strcpy() and memcpy() function?

606






Is there a way to have non-constant case labels (i.e. Ranges or arbitrary expressions)?

585


By using C language input a date into it and if it is right?

576


Why double pointer is used in c?

573


How do shell structures work?

575


What is header file in c?

608


show how link list can be used to repersent the following polynomial i) 5x+2

1683


Simplify the program segment if X = B then C ← true else C ← false

2590


What is static memory allocation?

611


Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the maximum number of concurrent threads that the InnoDB plug-in can create.

1484


What is a wrapper function in c?

592