Get Email Subscription

Enter your email address:

Delivered by FeedBurner

Wednesday, April 21, 2010

This program is used for Matrix Multiplication. (C++)


This program is used for Matrix Multiplication. (C++)
 
#include< iostream.h>
#include< conio.h>
#include< iomanip.h> 
 
 
 
struct matrix
{
int arr[3][3];// Double dimensional array 
};
matrix operator * (matrix a,matrix b); //Operator overloding
 
// function declaration for printing matrix
void matprint(matrix p);
 
void main()
{
clrscr();
// Declaring matrix values 
matrix a={ 1,1,3,
4,5,7,
2,9,6
};
matrix b={ 2,3,8,
7,4,1,
1,5,6
};
 
matrix c,d;
//overloaded operator will be called 
c=a*b;
//display the matrix
matprint(c);
}
//overloaded operator defination for matrix Multiplication
 
matrix operator *(matrix a, matrix b)
{
matrix c;
int i, j,k;
for(i=0;i< 3;i++)
{
for(j=0;j< 3;j++)
{
c.arr[i][j]=0;
for(k=0;k< 3;k++)
c.arr[i][j]+=a.arr[i][j]*b.arr[i][j];
}
}
return c;
}
 
//displaying matrix 
void matprint(matrix p)
{
int i,j;
cout< < endl< < endl;
for(i=0;i< 3;i++)
{ cout< < endl;
for(j=0;j< 3;j++)
cout< < setw(5)< < p.arr[i][j];
}
}
 
 
 
 
--------------------------------------------------------------------------------
 
 
The output of the programe will be ::
 
 
12      22      27
50      67      79      
73      72      61

Related Posts by Categories



0 comments:

About This Blog

Lorem Ipsum

  © Blogger templates Newspaper III by Ourblogtemplates.com 2008

Back to TOP