Matrix Multiplication in C using function

#include "stdio.h"

void matmul(int[][],int[][],int,int,int,int);

main()
{
int matrix_1[20][20],matrix_2[20][20],i,j,r1,r2,c1,c2;
printf("Enter the number of rows and columns of first matrix :\t");
scanf("%d%d",&r1,&c1);
printf("Enter the number of rows and columns of second matrix :\t");
scanf("%d%d",&r2,&c2);
if(c1==r2)
{
printf("Enter the elements of first matrix :\n");
for(i=0;i
{
for(j=0;j
{
scanf("%d",&matrix_1[i][j]);
}

}
printf("The first matrix is :\n");
for(i=0;i
{
for(j=0;j
{
printf("%d\t",matrix_1[i][j]);
}
printf("\n");

}

printf("Enter the elements of first matrix :\n");
for(i=0;i
{
for(j=0;j
{
scanf("%d",&matrix_2[i][j]);
}
}
printf("The second matrix is :\n");
for(i=0;i
{
for(j=0;j
{
printf("%d\t",matrix_2[i][j]);
}
printf("\n");
}

matmul(matrix_1,matrix_2,r1,c1,r2,c2);
}
else
printf("Multiplication not possible.\n");
}

void matmul(int num1[20][20],int num2[20][20],int r1,int c1,int r2,int c2 )
{
int k,c[30][30],i,j;


printf("The product matrix is :\n");
c[i][j]=0;
for(i=0;i
{
for(j=0;j
{
for(k=0;k
{
c[i][j]=c[i][j]+(num1[i][k]*num2[k][j]);
}
}
}
for(i=0;i
{
for(k=0;k
{
printf("%d\t",c[i][k]);
}
printf("\n");
}
}

Related Links :

4 comments:


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!!!