Let Us C (Chapter 8 : Arrays) : Program-13_2

(2)Write a program to multiply any two 3 x 3 matrices.

let us c chapter 8 arrays problem 13_2



// Let Us C (Chapter 8 : Arrays) : Program-13_2
/* (2)Write a program to multiply any two 3 x 3 matrices. */
#include<stdio.h>
#include<conio.h>
void main()
{
	int M1[3][3], M2[3][3], M3[3][3], i,j,k,sum;
	clrscr();
	printf("\nProgram for Multiplication of Matrices");
	printf("\nEnter two 3 X 3 matrices");
	printf("\nEnter 9 elements of 1st Matrix separated by space\n");
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			//printf(" Enter Element %d : ",M1[i][j]);
			scanf("%d",&M1[i][j]);
		}
	}
	printf("\nEnter 9 elements of 2nd Matrix separated by space\n");
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			//printf(" Enter Element %d : ",M2[i][j]);
			scanf("%d",&M2[i][j]);
		}
	}
	printf("***** 1st Matrix *****\n");
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			printf("%4d",M1[i][j]);
		}
		printf("\n");
	}
	printf("***** 2nd Matrix *****\n");
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			printf("%4d",M2[i][j]);
		}
		printf("\n");
	}
	printf("***** Multiplication of Matrices *****\n");
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			sum = 0;
			for(k=0;k<3;k++)
			{
				sum = sum + M1[i][k]*M2[k][j];
			}
			M3[i][j] = sum;
			printf("%4d",M3[i][j]);
		}
		printf("\n");
	}
}
OUTPUT

let us c chapter 8 arrays problem 13_2 output




Comments

Popular posts from this blog

Chapter 5 : Functions & Pointers (Let us C)

Let Us C (Chapter 8 : Arrays) : Program-9

Chapter 3: The Loop Control Structure (Let Us C)