Professional Documents
Culture Documents
import java.io.*;
public class Gausssian_Elimination
{
public static void main() throws IOException
{
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.println("What is the size of the system(n)?????");
int n=Integer.parseInt(br.readLine());
float a[][],b[],x[];
a=new float[n][n];
b=new float[n];
x=new float[n];
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
System.out.print("Enter the element for a["+i+"]["+j+"]");
a[i][j]=Float.parseFloat(br.readLine());
}
}
for(int i=0;i<n;i++)
{
System.out.print("Enter the element for b["+i+"]");
b[i]=Float.parseFloat(br.readLine());
}
gauss(n,a,b,x);
System.out.println("Solution vector for X");
for(int i=0;i<n;i++)
System.out.print(x[i]+" ");
}
x[k]=(b[k]-sum)/a[k][k];
}
return;
}
}
SAMPLE OUTPUT: