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


Please Help Members By Posting Answers For Below Questions

What is the use of typedef in structure in c?

549


Is main is user defined function?

599


What is c system32 taskhostw exe?

597


How a string is stored in c?

592


What is volatile variable in c?

660






Write an algorithm for implementing insertion and deletion operations in a singly linked list using arrays ?

3058


How do shell structures work?

572


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

1463


Differentiate between a for loop and a while loop? What are it uses?

677


Can you please explain the difference between exit() and _exit() function?

596


What is console in c language?

614


What is the size of enum in c?

625


Tell me what is null pointer in c?

617


Which one would you prefer - a macro or a function?

606


Explain argument and its types.

608