Contoh program sederhana matriks c++

matriks c++

Kali ini saya akan share program yang sangat sederhana yaitu contoh matriks c++ semoga apa yang kami share bermanfaat bagi Anda semua.

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

#include<stdlib.h>

using namespace std;

main()

{

 int pilihan;

 cout<<"**********MENGHITUNG DETERMINAN MATRIKS***********";

 cout<<"1. Matriks 2x2";

 cout<<"2. Matriks 3x3";

 cout<<"Ketik exit untuk keluar";


 cout<<"Pilihan Anda [1..2..exit]=";

 cin>>pilihan;


 if (pilihan==1)

 {

  int a,b,c,d;

  cout<<"Masukan Elemen Matriks =";

  cout<<"Elemen Matrik Baris 1 Kolom 1 =";

  cin>>a;

  cout<<"Elemen Matrik Baris 1 Kolom 2 =";

  cin>>b;

  cout<<"Elemen Matrik Baris 2 Kolom 1 =";

  cin>>c;

  cout<<"Elemen Matrik Baris 2 Kolom 2 =";

  cin>>d;


  cout<<"Matriks x "<<a<<" "<<b<<endl;

  cout<<"    "<<c<<" "<<d<<endl<<endl;


  cout<<"Determinan Matriks x ="<<(a*d)-(b*c);


 }

 else if (pilihan==2)

 {

  int a,b,c,d,e,f,g,h,i;

  cout<<"Masukan Elemen Matriks =";

  cout<<"Elemen Matrik Baris 1 Kolom 1 =";

  cin>>a;

  cout<<"Elemen Matrik Baris 1 Kolom 2 =";

  cin>>b;

  cout<<"Elemen Matrik Baris 1 Kolom 3 =";

  cin>>c;

  cout<<"Elemen Matrik Baris 2 Kolom 1 =";

  cin>>d;

  cout<<"Elemen Matrik Baris 2 Kolom 2 =";

  cin>>e;

  cout<<"Elemen Matrik Baris 2 Kolom 3 =";

  cin>>f;

  cout<<"Elemen Matrik Baris 3 Kolom 1 =";

  cin>>g;

  cout<<"Elemen Matrik Baris 3 Kolom 2 =";

  cin>>h;

  cout<<"Elemen Matrik Baris 3 Kolom 3 =";

  cin>>i;


  cout<<"Matriks x "<<a<<" "<<b<<" "<<c<<endl;

  cout<<"    "<<d<<" "<<e<<" "<<f<<endl;

  cout<<"    "<<g<<" "<<h<<" "<<i<<endl<<endl;


  cout<<"Determinan Matriks x ="<<(a*e*i+b*f*g+c*d*h)-(c*e*g+b*d*i+a*f*h);

 }

 else

 {

  exit;

 }

}

Leave A Comment