write a program in c language for the multiplication of two
matrices using pointers?
Answer Posted / sharanya
#include<stdio.h>
#include<conio.h>
#define row 50
#define column 50
void main()
{
int A[row][column],B[row][column],r1,r2,c1,c2,i,j;
void add(int A[row][column],int B[row][column],int c1,int r1);
clrscr();
printf("Enter Row and Column Sizes of A,B : ");
scanf("%d%d%d%d",&r1,&r2,&c1,&c2);
printf("Enter Elements Of A : ");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
scanf("%d",&A[i][j]);
}
}
printf("Enter Elements of B : ");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
scanf("%d",&B[i][j]);
}
}
if(r1==r2 && c1==c2);
else
printf("Addition is Not Possible.");
if(r2==c1)
{
multi(A,B,r1,r2,c2);
}
else
printf("Multiplication is Not Possible.");
}
void add(int A[row][column],int B[row][column],int r1,int c1)
{
int i,j;
printf("Addition Of Two Matrices: \n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf("\t%d",A[i][j]+B[i][j]);
}
print("\n");
}
}
void multi(int A[row][column],int B[row][column],int r1,int r2,int c2)
{
int C[row][column],i,j,k;
printf("Multiplication of Two Matrices : \n");
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
C[i][j]=0;
for(k=0;k<r2;k++)
C[i][j]=C[i][j]+A[i][k]*B[k][j];
printf("\t%d",C[i][j]);
}
printf("\n");
}
}
Is This Answer Correct ? | 4 Yes | 18 No |
Post New Answer View All Answers
What is the use of typedef in structure in c?
Is main is user defined function?
What is c system32 taskhostw exe?
How a string is stored in c?
What is volatile variable in c?
Write an algorithm for implementing insertion and deletion operations in a singly linked list using arrays ?
How do shell structures work?
WHICH TYPE OF JOBS WE GET BY WRITING GROUPS .WHEN THE EXAMS CONDUCTED IS THIS EXAMS ARE CONDUCTED EVERY YEAR OR NOT.PLS TELL ME THE ANSWER
Differentiate between a for loop and a while loop? What are it uses?
Can you please explain the difference between exit() and _exit() function?
What is console in c language?
What is the size of enum in c?
Tell me what is null pointer in c?
Which one would you prefer - a macro or a function?
Explain argument and its types.