0% found this document useful (0 votes)
3 views1 page

Problem 16

The document provides a C program that calculates the product of two matrices. It prompts the user to input the dimensions and elements of the matrices, checks if the multiplication is defined, and then computes and displays the resulting product matrix. The program includes necessary loops for matrix input and multiplication operations.

Uploaded by

sahritij
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Problem 16

The document provides a C program that calculates the product of two matrices. It prompts the user to input the dimensions and elements of the matrices, checks if the multiplication is defined, and then computes and displays the resulting product matrix. The program includes necessary loops for matrix input and multiplication operations.

Uploaded by

sahritij
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PROBLEM-16

Write a C-program to find the product of any two matrices .

Answer :

//Program to find the product of two matrices


//Bangabasi College, Dept. of Mathematics
#include<stdio.h>
int main()
{
int i,j,m,n,p,q,k;
float a[10][10],b[10][10],c[10][10];
printf("Enter the number of rows and columns of 1st matrix respectively:\t");
scanf("%d %d",&m,&n);
printf("Enter the number of rows and columns of 2nd matrix respectively:\t");
scanf("%d %d",&p,&q);
if(n!=p)
printf("Product of these two matrices is not defined");
else
{
printf("Product of these two matrices is defined\n");
printf("\nEnter the elements of 1st matrix row-wise:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf("%f",&a[i][j]);
}
printf("\nEnter the elements of 2nd matrix row-wise:\n");
for(i=0;i<n;i++)
{
for(j=0;j<q;j++)
scanf("%f",&b[i][j]);
}
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
c[i][j]=0.0;
for(k=0;k<n;k++)
c[i][j]+=a[i][k]*b[k][j];
}
}
printf("\nProduct of these two matrices is\n");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
printf("%f\t",c[i][j]);
printf("\n");
}
}
return 0;
}

You might also like