Simplest code for Gauss Elimination
100 % working
#include
#include
#include
#include
int main()
{
clrscr();
float a[20][20],x[20],t,sum;
int i,j,k,n;
cout<<"Enter no: of unknowns:\n\t";
cin>>n;
cout<<"\n enter elements of A"<
//scanning
for(i=0;i
{ cout<<"\n\t";
for(j=0;j
cin>>a[i][j];
}
//traingulaising
for(j=0;j
for(i=j+1;i
{ t=a[i][j]/a[j][j];
for(k=0;k
{ a[i][k]-=a[j][k]*t;
}
}
for(i=0;i<40;i++)
cout<<"=";
//displaying triangulised matrix
cout<<"\n Triangulaised matrix"<
for(i=0;i<40;i++)
cout<<"=";
for(i=0;i
{ cout<<"\n\n";
for(j=0;j
{ cout<<<
}
}
//back sub
for(i=n-1;i>=0;i--)
{
sum=0;
for(j=i+1;j
sum+=a[i][j]*x[j];
x[i]=(a[i][n]-sum)/a[i][i];
}
cout<<"\n";
for(i=0;i<40;i++)
cout<<"=";
cout<<"\n\t Result"<
for(i=0;i
cout<<
getch();
return 1;
}
100 % working
#include
#include
#include
#include
int main()
{
clrscr();
float a[20][20],x[20],t,sum;
int i,j,k,n;
cout<<"Enter no: of unknowns:\n\t";
cin>>n;
cout<<"\n enter elements of A"<
//scanning
for(i=0;i
{ cout<<"\n\t";
for(j=0;j
cin>>a[i][j];
}
//traingulaising
for(j=0;j
for(i=j+1;i
{ t=a[i][j]/a[j][j];
for(k=0;k
{ a[i][k]-=a[j][k]*t;
}
}
for(i=0;i<40;i++)
cout<<"=";
//displaying triangulised matrix
cout<<"\n Triangulaised matrix"<
for(i=0;i<40;i++)
cout<<"=";
for(i=0;i
{ cout<<"\n\n";
for(j=0;j
{ cout<
}
}
//back sub
for(i=n-1;i>=0;i--)
{
sum=0;
for(j=i+1;j
sum+=a[i][j]*x[j];
x[i]=(a[i][n]-sum)/a[i][i];
}
cout<<"\n";
for(i=0;i<40;i++)
cout<<"=";
cout<<"\n\t Result"<
for(i=0;i
cout<
getch();
return 1;
}
Be the first to comment on "Gauss Elimination in CPP"