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
Write a program to generate the Fibinocci Series
Write a C program on Centralized OLTP, Decentralized OLTP using locking mechanism, Semaphore using locking mechanism, Shared memory, message queues, channel of communication, sockets and a simple program on Saving bank application program using OLTP in IPC?
the statement while(i) puts the entire logic in loop. this loop is called a) indefinite loop b) definite loop c) loop syntax wrong d) none of the above
How can I get back to the interactive keyboard if stdin is redirected?
What is nested structure with example?
Why is c so popular?
In c programming language, how many parameters can be passed to a function ?
Why do some versions of toupper act strangely if given an upper-case letter?
What are the features of c languages?
Explain how can type-insensitive macros be created?
Write the control statements in C language
Why enum is used in c?
What are the uses of null pointers?
What is the correct code to have following output in c using nested for loop?
if a is an integer variable, a=5/2; will return a value a) 2.5 b) 3 c) 2 d) 0