Saturday, August 20, 2011

Program to find Multiplication of two matrices using function.

//Program to find Multiplication of two matrices using function.
#include<stdio.h>
#include<conio.h>
void mul();
void main()
{
 int a[3][3],b[3][3],i,j,m=3,n=3;
 clrscr();
 printf("Enter the elements of matrix a");
  for(i=0;i<m;i++)
  for(j=0;j<n;j++)
   scanf("%d",&a[i][j]);

 printf("Enter the elements of matrix b");
 for(i=0;i<m;i++)
  for(j=0;j<n;j++)
   scanf("%d",&b[i][j]);

 printf("matrix A:\n");
 for(i=0;i<m;i++)
 {
  for(j=0;j<n;j++)
   printf(" %d ",a[i][j]);
  printf("\n");
 }
 printf("matrix b:\n");
 for(i=0;i<m;i++)
 {
  for(j=0;j<n;j++)
   printf(" %d ",b[i][j]);
  printf("\n");
 }

 mul(a,m,n,b);
 getch();
}

void mul(a,m,n,b)
int m,n, a[][3],b[][3];
{
int i,j,k;
int c[3][3];
 for(i=0;i<m;i++)
 {
 for(j=0;j<n;j++)
 {
  c[i][j]=0;
  for(k=0;k<n;k++)
  { c[i][j]+=a[i][k]*b[k][j];}
 }
 }
  printf("mul of matrix:\n");

  for(i=0;i<m;i++)
 {
  for(j=0;j<n;j++)
   printf(" %d ",c[i][j]);
  printf("\n");
 }
}

Previous Next Home
0 Comments
Comments

Leave a Comment

:)) ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* :| 8-} :)] ~x( :-t b-( :-L x( =))

Twitter Delicious Facebook Favorites More