Sunday, 13 October 2013

PROGRAM TO PERFORM MULTIPLICATION OF TWO MATRICES

//PROGRAM TO PERFORM MULTIPLICATION OF TWO MATRICES
//Developed By Ahlam Ansari
class Multiplication
{
    int[ ][ ] a={{1,2,3,4},{2,3,4,5}};
    int[ ][ ] b={{1,1},{4,5},{3,4},{2,8}};
    int[ ][ ] c={{0,0},{0,0}};
    int i,j,k;
    void calculate( )
    {
        for(i=0;i<2;i++)
        {
            for(k=0;k<2;k++)
            {
                for(j=0;j<4;j++)
                {
                    c[i][k]=c[i][k]+a[i][j]*b[j][k];
                }
            }
        }
    }
   
    void show( )
    {
        System.out.println("Multiplication of two matrices is: ");
        for(i=0;i<2;i++)
        {
            for(j=0;j<2;j++)
            {
                System.out.print(" "+c[i][j]);
            }
            System.out.println( );
        }
    }
}

class MultiplyArray
{
    public static void main(String ahlam[ ])
    {
        Multiplication m= new Multiplication( );
        m.calculate( );
        m.show( );
    }
}

/*
C:\Users\Ahlam\Google Drive\My Lectures\Fall\OOPM\Programs>javac MultiplyArray.j
ava

C:\Users\Ahlam\Google Drive\My Lectures\Fall\OOPM\Programs>java MultiplyArray
Multiplication of two matrices is:
 26 55
 36 73

C:\Users\Ahlam\Google Drive\My Lectures\Fall\OOPM\Programs>
*/

No comments:

Post a Comment