#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <windows.h>
using namespace std;
void gotoxy (int x, int y)
{
COORD coord = {0, 0};
coord.X = x; coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void menu();
void matrix();
void loop();
void array1();
void exit();
void menu()
{
system("cls");
int pilih;
gotoxy (50,10);
cout<<" 1. Matriks \n";
gotoxy (50,11);
cout<<" 2. Loop \n";
gotoxy (50,12);
cout<<" 3. Array \n";
gotoxy (50,13);
cout<<" 4. Exit \n";
gotoxy (50,14);
cout<<"Pilih [1/2/3] = ";
cin >>pilih;
if(pilih == 1)
{
matrix();
}
else if (pilih == 2)
{
loop();
}
else if (pilih == 3)
{
array1();
}
else
{
cout<<"Salah input ";
}
}
void matrix()
{
system("cls");
int x,y;
int matriks [10] [10], matriksY[10] [10], MatriksHasil [10] [10];
cout<<"Masukkan baris A= ";
cin>>x;
cout<<"Masukkan kolom A= ";
cin>>y;
for(int bar=1; bar <=x; bar++)
{
for (int kol=1; kol<=y; kol++)
{
cout<<"mA["<<bar<<"]["<<kol<<"]= ";
cin>>matriks[bar][kol];
}
cout<<endl;
}
for(int bar=1; bar <=x; bar++)
{
for (int kol=1; kol<=y; kol++)
{
cout<<matriks[bar][kol]<<" ";
}
cout<<endl;
}
int det = ((matriks[1][1]*matriks[2][2]) - (matriks[1][2]*matriks[2][1]));
cout<<endl;
cout<<"("<<matriks[1][1]<<"*"<<matriks[2][2]<<")"<<"-"<<"("<<matriks[1][2]<<"*"<<matriks[2][1]<<")"<<"="<<det<<endl;
cout<<"Jumlah Determinan Matriks= \n"<<det<<endl;
if (det == 0)
{
cout<<"Matriks Tidak Memiliki Invers\n";
}
else
{
cout<<"Matriks Memiliki Invers\n";
matriksY[1][1] = matriks[2][2];
matriksY[1][2] = -(matriks[1][2]);
matriksY[2][1] = -(matriks[2][1]);
matriksY[2][2] = matriks[1][1];
for(int bar=1; bar <=x; bar++)
{
for (int kol=1; kol<=y; kol++)
{
cout<<matriksY[bar][kol]<<" ";
}
cout<<endl;
}
for(int bar=1; bar<=x; bar++)
{
for (int kol=1; kol<=y; kol++)
{
MatriksHasil[bar][kol] = (matriksY[bar][kol]) /det;
}
cout<<endl;
}
cout<<"Jumlah Invers Matriks= \n";
for(int bar=1; bar<=x; bar++)
{
for (int kol=1; kol<=y; kol++)
{
cout<<MatriksHasil[bar][kol]<<" ";
}
cout<<endl;
}
}
cout<<endl;
char kembali;
cout<<"kembali ke menu [y/t] ? " ;
cin>>kembali;
if(kembali=='y')
{
matrix();
}
else
{
menu();
}
}
void loop()
{
system("cls");
gotoxy (50,10);
cout<<"for\n";
char kembali;
gotoxy (40,11);
cout<<"kembali ke menu [y/t] ? " ;
cin>>kembali;
if(kembali=='y')
{
loop();
}
else
{
menu();
}
}
void array1()
{
system("cls");
gotoxy (50, 10);
cout<<"array\n";
char kembali;
gotoxy (40,11);
cout<<"kembali ke menu [y/t] ? " ;
cin>>kembali;
if(kembali=='y')
{
array1();
}
else
{
menu();
}
}
void exit()
{
exit();
}
main()
{
menu();
}