Program Perkalian Matriks A ordo 3x3 dan matriks B ordo 3x3



#include <iostream>

using namespace std;

void masukkan();
void perkalian();
void tampilanA();
void tampilanB();
void tampilanHasil();

int matriksA[3][3];
int matriksB[3][3];
int matrikshasil[3][3];

int main()
{
   masukkan();
   perkalian();
   tampilanA();
   tampilanB();
   tampilanHasil();
}

void masukkan()
{
    
    cout<<"Nilai matriks A"<<endl;
    for(int i=0; i<3; i++)
    {
        for(int j=0; j<3; j++)
        {
            cout<<"indeks ke-"<<i<<","<<j<<": ";
            cin>>matriksA[i][j];
        }
    }

    cout<<"\nmatriks B"<<endl;
    for(int i=0; i<3; i++)
    {
        for(int j=0; j<3; j++)
        {
            cout<<"indeks ke-"<<i<<","<<j<<": ";
            cin>>matriksB[i][j];
        }
    }
}

void perkalian()
{
    for(int i=0; i<4; i++)
    {
        for(int j=0; j<3; j++)
        {
            matrikshasil[i][j] = 0;
        }
    }

    for(int i=0; i<4; i++)
    {
        for(int j=0; j<3; j++)
        {
            for(int k=0; k<3; k++)
            {
                matrikshasil[i][j] = matrikshasil[i][j] + matriksA[k][j]*matriksB[k][j];
            }
        }
    }
}

void tampilanA()
{
    cout<<"\nTampilan matriks A:"<<endl;
        for(int i=0; i<3; i++)
    {
        for(int j=0; j<3; j++)
        {
            cout<<matriksA[i][j]<<" ";
        }
        cout<<endl;
    }
}

void tampilanB()
{
    cout<<"\nTampilan matriks B:"<<endl;
        for(int i=0; i<3; i++)
    {
        for(int j=0; j<3; j++)
        {
            cout<<matriksB[i][j]<<" ";
        }
        cout<<endl;
    }
}

void tampilanHasil()
{
    cout<<"\nHasil perkalian matriks A dengan B:"<<endl;
        for(int i=0; i<3; i++)
    {
        for(int j=0; j<3; j++)
        {
            cout<<matrikshasil[i][j]<<" ";
        }
        cout<<endl;
    }
}

Related Posts:

0 Response to "Program Perkalian Matriks A ordo 3x3 dan matriks B ordo 3x3 "

Posting Komentar

Thank you for reading the article in this post.
We hope you can leave comments about this post, so that it will be an evaluation material for us to make a better article for the future.

Report if there is an inactive link by commenting, we will immediately make improvements to the link.