#include <iostream.h>
#include <conio.h>
#define Nmaks 3
void main() {
typedef float matriks[Nmaks][Nmaks];
int i,j;
float determinan, hasilbagidet;
matriks A,a;
char answer;
do
{
do
{
clrscr();
cout<<"DETERMINAN MATRIKS A : "<<endl<<endl;
cout<<"Masukkan Nilai Matriks A : "<<endl;
for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
cout<<"A["<<i<<","<<j<<"] = ";
cin>>A[i][j];
}
}
clrscr();
cout<<endl;
//Proses Mencari Determinan Matriks A
determinan = (A[1][1] * A[2][2]) - (A[2][1] * A[1][2]);
}while (determinan == 0);
hasilbagidet = 1/determinan;
//mencari invers
a[1][1] = hasilbagidet * A[2][2];
a[1][2] = hasilbagidet * -A[1][2];
a[2][1] = hasilbagidet * -A[2][1];
a[2][2] = hasilbagidet * A[1][1];
clrscr();
//Output Matriks A
gotoxy(1,5);
cout<<"A = ";
for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
gotoxy(2+4*j,2+2*i);
cout<<A[i][j];
}
}
gotoxy(1,8);
cout<<"Determinan Matriks A = "<<determinan;
cout<<endl;
//Output Invers Matriks A
gotoxy(1,10);
cout<<"Invers Matriks A : "<<endl;
gotoxy(2,15);
cout<<"A^-1 = ";
for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
gotoxy(1+9*j,12+2*i);
cout<<a[i][j];
}
}
getch();
clrscr();
cout<<"== PROGRAM SELESAI =="<<endl<<endl;
cout<<"Mau Melakukan Perhitungan Lagi?? [Y/T] "; cin>>answer;
}
while ((answer == 'y') || (answer == 'Y'));
}
0 comments:
Posting Komentar