Write a program to multiply two arrays of 4*4

/*
PROGRAM:
——–
Write a program to multiply two arrays of 4*4.
*/
#include<stdio.h>
#include<conio.h>

void main()
{
int a[4][4],b[4][4],c[4][4]={0},i,j,k;
clrscr();

printf(“Please enter the values for Matrix A: “);
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
printf(“\nRow %d and Column %d: “,i+1,j+1);
scanf(“%d”,&a[i][j]);
}
}
printf(“Please enter the values for Matrix B: “);
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
printf(“\nRow %d and Column %d: “,i+1,j+1);
scanf(“%d”,&b[i][j]);
}
}
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
for(k=0;k<4;k++)
{
c[i][j]+=a[i][k]*b[k][j];
}
}
}
printf(“\n\nMultiplied Matrix: \n\n”);
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
printf(“%4d”,c[i][j]);
}
printf(“\n”);
}
getch();
}
/*
OUTPUT:
——-
Row 3 and Column 4: 1

Row 4 and Column 1: 1

Row 4 and Column 2: 2

Row 4 and Column 3: 3

Row 4 and Column 4: 4
Please enter the values for Matrix B:
Row 1 and Column 1: 0

Row 1 and Column 2: 0

Row 1 and Column 3: 0

Row 1 and Column 4: 0

Row 2 and Column 1: 1

Row 2 and Column 2: 1

Row 2 and Column 3: 1

Row 2 and Column 4: 1

Row 3 and Column 1: 2

Row 3 and Column 2: 2

Row 3 and Column 3: 2

Row 3 and Column 4: 3

Row 4 and Column 1: 3

Row 4 and Column 2: 3

Row 4 and Column 3: 0

Row 4 and Column 4: 0
Multiplied Matrix:

6 6 0 0
9 9 0 0
3 3 0 0
20 20 8 11
*/

Share

About the Author

Akash Padhiyar

Visit Website

There are no comments yet, add one below.

Leave a Comment

Your email address will not be published. Required fields are marked *

*

Time limit is exhausted. Please reload CAPTCHA.