Anda di halaman 1dari 3

Program C++ Untuk Mengimplementasikan Eliminasi Gauss Jordan

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

using namespace std;

int main()
{
int i, j, k, n;
float a[10][10]={0}, d;
cout <<
"=================================================================="
<< endl;
cout << " Program C++ Untuk Mengimplementasikan Eliminasi Gauss Jordan " << endl;
cout <<
"=================================================================="
<< endl;
cout << "

Kelas : Dik A Matematika 2011 " << endl;

cout << " " << endl;


cout << "Masukkan Banyak Persamaan : ";
cin >> n;
cout << " " << endl;
cout << "Masukkan semua koefisien dari matriks serta matriks b juga !" << endl;
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++)
cin >> a[i][j];

for (i = 1; i <= n; i++)


for (j = 1; j <= 2 * n; j++)
if(j == (i+n))
a[i][j] = 1;

for (i = n; i > 1; i--)


{
if (a[i-1][1] < a[i][1])
for (j = 1; j <= n * 2; j++)

{
d = a[i][j];
a[i][j]=a[i-1][j];
a[i-1][j] = d;
}
}

for (i = 1; i <= n; i++)


{
for (j = 1; j <= n * 2; j++)
if (j != i)
{
d = a[i][j] / a[i][i];
for (k = 1; k <= n * 2; k++)
a[j][k] -= a[i][k] * d;
}
}

for (i = 1; i <= n; i++)


{
d = a[i][i];
for (j = 1; j <= n * 2; j++)
a[i][j] = a[i][j] / d;
}

cout << " " << endl;


cout << "Solusinya adalah : " << endl;
for (i = 1; i <= n; i++)
{
for (j = n + 1; j <= n * 2; j++)
cout << a[i][j] << "
cout << endl;
}

getch();
return 0;

";