C Program FOR MATRIX MULTIPLICATION

C Program FOR MATRIX MULTIPLICATION



#include
main()
{
int a[20][20],b[20][20],c[20][20],r1,c1,c2,r2,i,j,k;
printf(“\tEnter the row and coloumn size For matrix1\n”);
scanf(“%d%d”,&r1,&c1);
printf(“\tEnter the row and coloumn size For matrix2\n”);
scanf(“%d%d”,&r2,&c2);
if (c1!=r2)
{
printf(“\tOppssss...The Coloumn size of Matrix1 not equal to row size of Matrix2\n\tMultiplication impossible/n”);
}
else
{
printf(“\tEnter elemnts of matrix1\n”);
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
scanf(“%d”,&a[i][j]);
}
}
printf(“\tEnter elements of matrix2\n”);
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
scanf(“%d”,&b[i][j]);
}
}
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
c[i][j]=0;
for(k=0;k<c1;k++)
{
c[i][j]+=a[i][k]*b[k][j];
}
}
}
printf(“\tYes...!! Product Matrix…\n”);
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
printf(“\t%d\t”,c[i][j]);
}
printf(“\n”);
}
}
}






OUTPUT:



Enter the row and coloumn size of matrix1
3
3
Enter the row and coloumn size of matrix2
3
3
Enter elemnts of matrix1
1
2
3
4
5
6
7
8
9

Enter elemnts of matrix2
9
8
7
6
5
4
3
2
1

Product Matrix…

30 24 18

84 69 54

138 114 90

Related Links :

1 comment:


If you face any Problem in viewing code such as Incomplete "For Loops" or "Incorrect greater than or smaller" than equal to signs then please collect from My Web Site CLICK HERE


More Useful Topics...

 

History Of C..

In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.

My 1st Program...


#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t*******Pankaj *******\n");
printf ("\t\t\t********************************\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}

Next Step...


#include
#include

void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");

printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");

getch ();

}

Hits!!!