Sunday, December 5, 2010

Product Matrix – Find the Product of Two Matrices

//TO WRITE A PROGRAM TO FIND THE PRODUCT OF TWO MATRICES

#include<iostream.h>

#include<conio.h>

void input(int t[][3]);

void product(int a[][3], int b[][3], int c[][3]);

void display(int [][3]);

void arrinit(int [][3]);

void main()

{

    int a[3][3], b[3][3], c[3][3];

    clrscr();

    cout << "Enter Values for Matrix 1 \n";

    input(a);

    cout << "Enter Values for Matrix 2 \n";

    input(b);

    product(a,b,c);

    cout << "\nProduct of two matrices are \n\n";

    display(c);

getch();

}

void input(int t[][3])

{

    int i, j;

    for(i=0; i<3; i++)

    {

        for(j=0; j<3; j++)

            cin >> t[i][j];

    }

}

void product(int a[][3], int b[][3], int c[][3])

{

    int i, j, k;

    for(i=0; i<3; i++)

    {

        for(j=0; j<3; j++)

        {

            c[i][j]=0;

            for(k=0; k<3; k++)

            {

                c[i][j] += a[i][k] * b[k][j];

            }

        }

    }

}

void display(int c[][3])

{

    int i, j;

    for(i=0; i<3; i++)

    {

        for(j=0; j<3; j++)

            cout << c[i][j] << " ";

    cout << "\n";

    }

}

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home