#include <iostream.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
main()
{
int i, j;
float x1, x2, x3, x4, p, a[8][8];
char c;
clrscr();
cout<<"======================================\n";
cout<<"Selamat datang di program GAUSS JORDAN\n";
cout<<"======================================\n\n";
cout<<" 2a + 4b + c = 68"<<endl;
cout<<" -a + 3b + 2c = 46"<<endl;
cout<<" 2a - 3b + 5c = 16\n\n";
cout<<"Bentuk persamaan: a + b + c = d"<<endl;
cout<<endl;
for(i=1;i<=3;i++)
{
cout<<"--------------\n";
cout<<"Persamaan ke-"<<i<<endl;
cout<<"--------------\n";
c='a';
for(j=1;j<=4;j++)
{
cout<<"Untuk nilai "<<c<<" = ";cin>>a[i][j];
c++;
}
cout<<endl;
}
clrscr();
cout<<"Proses 1"<<endl;
for(j=4;j>=1;j--)
{
a[1][j]=a[1][j]/a[1][1];
}
for(i=1;i<=4;i++)
{
if(i!=1)
{
p=a[i][1]/a[1][1];
for(j=1;j<=4;j++)
{
a[i][j]=a[i][j]-(p*a[1][j]);
}
}
}
for(i=1;i<=3;i++)
{
for(j=1;j<=4;j++)
{
printf(" %.2f ",a[i][j]);
}
cout<<endl;
}
cout<<""<<endl;
cout<<"Proses 2"<<endl;
for(j=4;j>=2;j--)
{
a[2][j]=a[2][j]/a[2][2];
}
for(i=1;i<=3;i++)
{
if(i!=2)
{
p=a[i][2]/a[2][2];
for(j=1;j<=4;j++)
{
a[i][j]=a[i][j]-(p*a[2][j]);
}
}
}
for(i=1;i<=3;i++)
{
for(j=1;j<=4;j++)
{
printf(" %.2f ",a[i][j]);
}
cout<<endl;
}
cout<<""<<endl;
cout<<"Proses 3"<<endl;
for(j=4;j>=3;j--)
{
a[3][j]=a[3][j]/a[3][3];
}
for(i=1;i<=3;i++)
{
if(i!=3)
{
p=a[i][3]/a[3][3];
for(j=1;j<=4;j++)
{
a[i][j]=a[i][j]-(p*a[3][j]);
}
}
}
for(i=1;i<=3;i++)
{
for(j=1;j<=4;j++)
{
printf(" %.2f ",a[i][j]);
}
cout<<endl;
}
cout<<""<<endl;
x3=a[3][4];
x2=a[2][4];
x1=a[1][4];
cout<<"Output Hasil"<<endl;
printf(" x1 = %.4f\n",x1);
printf(" x2 = %.4f\n",x2);
printf(" x3 = %.4f\n",x3);
getch();
return 0;
}
#include <stdio.h>
#include <conio.h>
#include <math.h>
main()
{
int i, j;
float x1, x2, x3, x4, p, a[8][8];
char c;
clrscr();
cout<<"======================================\n";
cout<<"Selamat datang di program GAUSS JORDAN\n";
cout<<"======================================\n\n";
cout<<" 2a + 4b + c = 68"<<endl;
cout<<" -a + 3b + 2c = 46"<<endl;
cout<<" 2a - 3b + 5c = 16\n\n";
cout<<"Bentuk persamaan: a + b + c = d"<<endl;
cout<<endl;
for(i=1;i<=3;i++)
{
cout<<"--------------\n";
cout<<"Persamaan ke-"<<i<<endl;
cout<<"--------------\n";
c='a';
for(j=1;j<=4;j++)
{
cout<<"Untuk nilai "<<c<<" = ";cin>>a[i][j];
c++;
}
cout<<endl;
}
clrscr();
cout<<"Proses 1"<<endl;
for(j=4;j>=1;j--)
{
a[1][j]=a[1][j]/a[1][1];
}
for(i=1;i<=4;i++)
{
if(i!=1)
{
p=a[i][1]/a[1][1];
for(j=1;j<=4;j++)
{
a[i][j]=a[i][j]-(p*a[1][j]);
}
}
}
for(i=1;i<=3;i++)
{
for(j=1;j<=4;j++)
{
printf(" %.2f ",a[i][j]);
}
cout<<endl;
}
cout<<""<<endl;
cout<<"Proses 2"<<endl;
for(j=4;j>=2;j--)
{
a[2][j]=a[2][j]/a[2][2];
}
for(i=1;i<=3;i++)
{
if(i!=2)
{
p=a[i][2]/a[2][2];
for(j=1;j<=4;j++)
{
a[i][j]=a[i][j]-(p*a[2][j]);
}
}
}
for(i=1;i<=3;i++)
{
for(j=1;j<=4;j++)
{
printf(" %.2f ",a[i][j]);
}
cout<<endl;
}
cout<<""<<endl;
cout<<"Proses 3"<<endl;
for(j=4;j>=3;j--)
{
a[3][j]=a[3][j]/a[3][3];
}
for(i=1;i<=3;i++)
{
if(i!=3)
{
p=a[i][3]/a[3][3];
for(j=1;j<=4;j++)
{
a[i][j]=a[i][j]-(p*a[3][j]);
}
}
}
for(i=1;i<=3;i++)
{
for(j=1;j<=4;j++)
{
printf(" %.2f ",a[i][j]);
}
cout<<endl;
}
cout<<""<<endl;
x3=a[3][4];
x2=a[2][4];
x1=a[1][4];
cout<<"Output Hasil"<<endl;
printf(" x1 = %.4f\n",x1);
printf(" x2 = %.4f\n",x2);
printf(" x3 = %.4f\n",x3);
getch();
return 0;
}
1 komentar:
Hey kawan,,, article mu bagus2,, saya tertarik,, dan saya mintag ijin untuk mengcopynya ya. . . semoga tidak keberatan.. klo sempet kunjungi balik ya,, atau add YM ku efran90_noz
terimakasih..
Berkomentar yang sopan ya, Terimakasih sahabat..
EmoticonEmoticon