Wednesday, 21 January 2015

Contoh script c++ Metode gauss Jordan

Metode gauss Jordan

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

void main()
{
char pil_pro;
float a11, a21, a12, a22, A11=1, A21=0, A12=0, A22=1;
float b11, b21, b12, b22, B11, B21, B12, B22;
float c11, c21, c12, c22, C11, C21, C12, C22;
float d11, d21, d12, d22, D11, D21, D12, D22;
float e11, e21, e12, e22, E11, E21, E12, E22;

cout<<"\n\t\t\tPROGRAM MATRIKS GAUSS JORDAN "<<endl;
cout<<"\t\t==========================================="<<endl<<endl;


ulang_masuk:
cout<<"\t(1,1) : ";
cin>>a11;
cout<<"\t(1,2) : ";
cin>>a21;
cout<<"\t(2,1) : ";
cin>>a12;
cout<<"\t(2,2) : ";
cin>>a22;

cout<<""<<endl;
cout<<"    ------------------"<<endl<<endl;
cout<<"\t["<<a11<<"\t"<<a21<<"]"<<endl;
cout<<"\t["<<a12<<"\t"<<a22<<"]"<<endl<<endl;
cout<<"    ------------------"<<endl;
cout<<"\n[U] Ulang masukkan angka  [L] Lanjutkan Penghitungan   |   Pilih  :  ";
cin>>pil_pro;
if (pil_pro=='U' || pil_pro=='u')
                 {goto ulang_masuk;}
else if (pil_pro=='L' || pil_pro=='l')
                 {goto next_satu;}
else
                 {goto end;}

//langkah pertama
next_satu:
ulang_satu:
cout<<""<<endl<<endl<<endl<<endl;
cout<<"\t|---------------|"<<endl;
cout<<"\t|Langkah pertama|"<<endl;
cout<<"\t|---------------|"<<endl<<endl;
cout<<"\t["<<a11<<"\t"<<a21<<" | "<<A11<<"\t"<<A21<<"]"<<endl;
cout<<"\t["<<a12<<"\t"<<a22<<" | "<<A12<<"\t"<<A22<<"]"<<endl<<endl;
cout<<"\tMengubah Kolum 1 dan baris 1 menjadi = 1"<<endl<<endl;
//hasil pertama
b11=a11/a11;b21=a21/a11;B11=A11/a11;B21=A21/a11;
b12=a12;b22=a22;B12=A12;B22=A22;
cout<<"\tHasilnya : "<<endl;
cout<<"\t--------"<<endl;
cout<<"\t["<<b11<<"\t"<<b21<<"|\t"<<B11<<"\t"<<B21<<"]"<<endl;
cout<<"\t["<<b12<<"\t"<<b22<<"|\t"<<B12<<"\t"<<B22<<"]"<<endl;
cout<<"\n\n\t[ U ] Ulang     [ L ] Lanjut   |   Pilih proses :  ";
cin>>pil_pro;
if (pil_pro=='U' || pil_pro=='u')
                 {goto ulang_satu;}
else if (pil_pro=='L' || pil_pro=='l')
                 {goto next_dua;}
else
                 {goto end;}


//langkah kedua
ulang_dua:
next_dua:
cout<<""<<endl<<endl<<endl<<endl;
cout<<"\t|-------------|"<<endl;
cout<<"\t|Langkah kedua|"<<endl;
cout<<"\t|-------------|"<<endl<<endl;
cout<<"\tMengubah Kolum 2 dan Baris 2 menjadi = 1"<<endl<<endl;
c11=b11;c21=b21;C11=B11;C21=B21;
c12=(b11*(-b12))+b12;c22=(b21*(-b12))+b22;
C12=(B11*(-B12))+B12;C22=(B21*(-B12))+B22;
cout<<"\tHasilnya : "<<endl;
cout<<"\t--------"<<endl;
cout<<"\t["<<c11<<"\t"<<c21<<" | "<<C11<<"\t"<<C21<<"]"<<endl;
cout<<"\t["<<c12<<"\t"<<c22<<" | "<<C12<<"\t"<<C22<<"]"<<endl;
cout<<"\n\n\t[ U ] Ulang     [ L ] Lanjut   |   Pilih proses :  ";
cin>>pil_pro;
if (pil_pro=='U' || pil_pro=='u')
                 {goto ulang_dua;}
else if (pil_pro=='L' || pil_pro=='l')
                 {goto next_tiga;}
else
                 {goto end;}

ulang_tiga:
next_tiga:
cout<<""<<endl<<endl<<endl<<endl;
cout<<"\t|--------------|"<<endl;
cout<<"\t|Langkah ketiga|"<<endl;
cout<<"\t|--------------|"<<endl<<endl;
cout<<"\tMengubah Kolom 3 dan Baris 3 menjadi = 1"<<endl<<endl;
d11=c11;d21=c21;D11=d11;D21=C21;
d12=c12/c22;d22=c22/c22;D12=C12/c22;D22=C22/c22;
cout<<"\tHasilnya : "<<endl;
cout<<"\t--------"<<endl;
cout<<"\t["<<d11<<"\t"<<d21<<" | "<<D11<<"\t"<<D21<<"]"<<endl;
cout<<"\t["<<d12<<"\t"<<d22<<" | "<<D12<<"\t"<<D22<<"]"<<endl;
cout<<"\n\n\t[ U ] Ulang     [ L ] Lanjut   |   Pilih proses :  ";
cin>>pil_pro;
if (pil_pro=='U' || pil_pro=='u')
                 {goto ulang_tiga;}
else if (pil_pro=='L' || pil_pro=='l')
                 {goto next_empat;}
else
                 {goto end;}


ulang_empat:
next_empat:
cout<<""<<endl<<endl<<endl<<endl;
cout<<"\t|-------------|"<<endl;
cout<<"\t|Langkah empat|"<<endl;
cout<<"\t|-------------|"<<endl<<endl;
cout<<"\tMengubah Kolom 4 dan Baris 4 menjadi = 1"<<endl<<endl;
e11=(d12*(-d11))+d11;e21=(d22*(-d12))+d21;
E11=(D12*(-d11))+d11;E21=(d22*(-d21))+D11;
e12=d12;e22=d22;E12=D12;E22=D22;
cout<<"\tJadi Hasil Inversrnya adalah : "<<endl;
cout<<"\t-----------------------------"<<endl;
cout<<"\t["<<e11<<"\t"<<e21<<" | "<<E11<<"\t"<<E21<<"]"<<endl;
cout<<"\t["<<e12<<"\t"<<e22<<" | "<<E12<<"\t"<<E22<<"]"<<endl;

end:
cout<<""<<endl<<endl<<endl;
cout<<"\t\t\tTerima Kasih telah menggunakan program ini :D"<<endl;
getche ();

}

Download script Link1 / Link2

No comments:

Post a Comment