Contoh program perkalian matriks c++

Kali ini kami akan share contoh program perkalian matriks c++, pada program sederhana ini kami akan mencari bagaimana mencari matriks dengan determinan.

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>

using namespace std;

main ()
{
 int matrixA [5][5], a, b, matrixB [10][10],c,d;;

    cout<<"-----------Matrix A-----------";
    cout<<"\nEnter the number of rows = ";
    cin>>a;
    cout<<"Enter the number of coulomn= ";
    cin>>b;

    cout<<"----------------------------------------------" <<endl;
    for(int bar=1;bar<=a;bar++)
    {
        for(int kol=1;kol<=b;kol++)
        {
            cout<<"MatrixA[" <<bar <<"][" <<kol <<"]=";
            cin>>matrixA [bar][kol];
        }
        cout<<endl;
    }

    system("cls");

    cout<<"-----------Matrix B-----------";
    cout<<"\nEnter the rows matriks B= ";
    cin>>c;
    cout<<"Enter the coulomn matriks B= ";
    cin>>d;

    cout<<"----------------------------------------------" <<endl;
    for(int row=1;row<=c;row++)
    {
        for(int col=1;col<=d;col++)
        {
            cout<<"mB[" <<row <<"][" <<col <<"]=";
            cin>>matrixB [row][col];
        }

        cout<<endl;
    }
 
 system("cls");

    if(a==c && b==d)
    {
        cout<<"-Matrix A-" <<endl;
        for(int bar=1;bar<=a;bar++)
        {
            for(int kol=1;kol<=b;kol++)
            {
                cout<<matrixA[bar][kol] <<" ";
            }
            cout<<endl;
        }

        cout<<endl <<endl;

        cout<<"-Matrix B-" <<endl;
        for(int row=1;row<=c;row++)
        {
            for(int col=1;col<=d;col++)
            {
                cout<<matrixB[row][col] <<" ";
            }
            cout<<endl;
        }

        cout<<endl <<endl;
        cout<<"----------------------------------------------" <<endl;
       
  int x = 1, detA, detB;

  detB= (matrixB[1][1]* matrixB[2][2] - matrixB[1][2] * matrixB [2][1]);

  cout<<"det A = det B" <<endl;

  cout<<"matrixA[1][1]" <<"x kuadrat - " <<matrixA[1][2]* matrixA[2][1] <<" = " <<detB <<endl;
 
  int y= detB + matrixA[1][2] * matrixA[2][1];
 
  cout<<matrixA[1][1] <<" x kuadrat = " <<y <<endl;
 
  cout<<"x kuadrat = " <<y/matrixA[1][1] <<endl;
 
  x= sqrt (y/matrixA [1][1]);
 
  cout<<"x = " <<x;
 }
}
Default image
Arman Basir
A New Journey. Menyukai hal-hal baru yang menantang dan kompleks untuk di pecahkan

Leave a Reply