Multiplication of Matrix

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Experiment No:14

Multiplication of Matrix
Aim: Write a program to print Multiplication of two
matrices read by user.

Theory:
For Loop: The for loop provides a
functionality/feature to repeat a set of statements a defined
number of times. The for loop is in itself a form of an entry-
controlled loop.
Array:

Syntax:
for( initialization; check/test expression; updation )
{
// body consisting of multiple statements
}

Algorithm:
Flowchart:

Program:
#include<stdio.h>
void accept( int x[10][10], int r ,int c )
{
int i,j;

for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&x[i][j]);
}
}
}
void display( int x[10][10], int r, int c )
{
int i,j;

for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%d",x[i][j]);
printf("\t");
}
printf("\n");
}
}
void multiplication( int a[10][10], int b[10][10], int
mul[10][10], int p, int q, int m, int n )
{
int i,j,k;
printf("Matrix Mulitplication:");

for(i=0;i<p;i++)
{
for(j=0;j<n;j++)
{
mul[i][j]=0;

for(k=0;k<q;k++)
{
mul[i][j] = mul[i][j] + a[i][k]*b[k]
[j];
}
}
}
printf("\n");
}
int main()
{
int a[10][10], b[10][10], mul[10][10], p, q, m, n,
i, j, k;

printf("Input number of elements in first row and


column of first matrix:\n");
scanf("%d\n%d",&p,&q);
printf("Input number of elements in first row and
column of second matrix:\n");
scanf("%d\n%d",&m,&n);

if(q==m)
{
printf("\n");
accept(a,p,q);
printf("\n");
accept(b,m,n);

printf("\nFirst matrix: \n");


display(a,p,q);
printf("\nSecond matrix: \n");
display(b,m,n);
printf("\n");
multiplication(a,b,mul,p,q,m,n);
display(mul,p,n);
}
else
{
printf("Matrix multipication of givent two
matrices is not possible!");
}
}
Output:
Conclusion:
 For loop is an Entry-Controlled Loop
 It requires 3 conditions parameters i.e. check expression,
conditional statement, and urinary operators for updation.
 Its workflow is an initialization, check/test, and then updation.

You might also like