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
Where are c variables stored in memory?
What is the most efficient way to count the number of bits which are set in an integer?
What is difference between Structure and Unions?
How can you determine the size of an allocated portion of memory?
What is an arrays?
Why & is used in c?
How to get string length of given string in c?
What is volatile c?
I need a sort of an approximate strcmp routine?
Where in memory are my variables stored?
Program will then find the largest of three numbers using nested if-else statements. User is prompted to enter three numbers. Program will find the largest number and display it on the screen. All three numbers entered by the user are also displayed. If user enters 21, 33, and 5, the output should be as follows: You entered: 21, 33 and 5. The largest number is 33.
A variable that is defined in a specified portion of a program but can be used throughout the program a) global variable b) local variable c) character d) none
What should malloc(0) do?
What is array in c with example?
How can I access an I o board directly?