IndexPrevious

Programs in C language

17. Program to find Product of two matrices.

#include<stdio.h>
void main()
{
	int a[3][3],b[3][3],c[3][3],i,j,k;
    clrscr();
    printf("Enter values for Matrix A:");
    for(i=0;i<3;i++)
    for(j=0;j<3;j++)
    scanf("%d",&a[i][j]);
    
    printf("Enter values for Matrix B:");
    for(i=0;i<3;i++)
    for(j=0;j<3;j++)
    scanf("%d",&b[i][j]);
	
	for(i=0;i<3;i++)
    for(j=0;j<3;j++)
	{
		c[i][j]=0;
		for(k=0;k<3;k++)
		c[i][j]=c[i][j]+a[i][k]*b[k][j];
    }
    
    printf("The result matrix:");
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		printf("\t%d",c[i][j]);
		printf("\n");
	}
    
    getch();
}
Father of C Language
Dennis Ritchie

Dennis Ritchie

Born: September 9, 1941, Bronxville
Died: October 9, 2011, Murray Hill
Google+