#include <iostream>
#include<cstdlib>
#include<cmath>
#include<conio.h>
using namespace std;
int main()
{
int i,j,k,n;
double tmp, x, a[20][20],z,y[10];
cout<<"\nInsert size of matrix : ";
cin>>n;
cout<<("\nInsert Matrix x : \n");
for(i=1; i<=n; i++)
{
for(j=1; j<=(n); j++)
{
cout<<" X["<<i<<"]["<<j<<"] :";
cin>>a[i][j];
}
}
cout<<"\nInsert Matrix Y : ";
for(int i=1;i<=n;i++){
cout<<" Y["<<i<<"]["<<j<<"] :";
cin>>y[i];
}
cout<<"\n";
cout<<"\nThe Matrix : "<<endl;
for (int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cout<<a[i][j]<<"\t";
}
cout<<"|b"<<i<<"|";
cout<<"\t"<<y[i]<<endl;
}
cout<<endl;
for(int i=1;i<=n;i++){
cout<<"\nStep "<<i<<endl;
tmp=a[i][i];
for(int j=1;j<=n;j++){
a[i][j]=a[i][j]/tmp;
}
y[i]=y[i]/tmp;
for (int z=0;z<=n;z++){
if(z!=i){
tmp=a[z][i];
for(int j=i;j<=n;j++){
a[z][j]=a[z][j]-(tmp*a[i][j]);}
y[z]=y[z]-(tmp*(y[i]));
}
}
for (int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cout<<a[i][j]<<"\t";
}
cout<<"|b"<<i<<"|";
cout<<"\t"<<y[i]<<endl;
}
cout<<endl;
}
cout<<"\nThe results :"<<endl;
for(int i=1;i<=n;i++){
cout<<"X"<<i<<" = "<<y[i]<<endl;
}
getch();
}
Tidak ada komentar:
Posting Komentar
Catatan: Hanya anggota dari blog ini yang dapat mengirim komentar.