In this post, we will write a C++ program for Matrix Multiplication.

C++ program for Matrix Multiplication


C++ program for Matrix Multiplication.

#include<iostream>
#include<conio.h>
#include<stdio.h>

int main()
{
    system("cls");

    int a[3][3] = {{1,2,3},{4,5,6},{7,8,9}};
    int b[3][3];
    int i,j,k;

    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            b[i][j] = 0;
            for(k=0;k<3;k++)
            {
                b[i][j] += a[i][k]*a[k][j];
            }
        }
    }
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            std::cout<<"\t"<<b[j][i];
        }
        std::cout<<"\n";
    }

    getch();
    return 0;
}



Output

30 66 102
36 81 126
42 96 150