import java.util.Scanner;
public class bkl{
public static void main(String args [])throws Exception
{
matrix data=new matrix();
data.readdata();
data.del123();
data.showdata();
}
}
class matrix
{
int i,j,k,del,del1,del2,del3;
int a[][]=new int[3][4];
int c[][]=new int[3][4];
void readdata() throws Exception
{
Scanner in=new Scanner(System.in);
for(i=0;i<3;i++)
{
System.out.println("Enter the line(a"+(i+1)+"x+b"+
(i+1)+"y+c"+(i+1)+"z=d"+(i+1)+")");
for(j=0;j<4;j++)
{
c[i][j]=a[i][j]=in.nextInt();
}
}
del=a[0][0]*(a[1][1]*a[2][2]-a[1][2]*a[2][1])
-a[0][1]*(a[1][0]*a[2][2]-a[2][0]*a[1][2])
+a[0][2]*(a[1][0]*a[2][1]-a[2][0]*a[1][1]);
}
void del123()
{
for(i=0;i<3;i++)
a[i][0]=c[i][3];
del1=a[0][0]*(a[1][1]*a[2][2]-a[1][2]*a[2][1])
-a[0][1]*(a[1][0]*a[2][2]-a[2][0]*a[1][2])
+a[0][2]*(a[1][0]*a[2][1]-a[2][0]*a[1][1]);
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
a[i][j]=c[i][j];
}
}
for(i=0;i<3;i++)
a[i][1]=c[i][3];
del2=a[0][0]*(a[1][1]*a[2][2]-a[1][2]*a[2][1])
-a[0][1]*(a[1][0]*a[2][2]-a[2][0]*a[1][2])
+a[0][2]*(a[1][0]*a[2][1]-a[2][0]*a[1][1]);
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
a[i][j]=c[i][j];
}
}
for(i=0;i<3;i++)
a[i][2]=c[i][3];
del3=a[0][0]*(a[1][1]*a[2][2]-a[1][2]*a[2][1])
-a[0][1]*(a[1][0]*a[2][2]-a[2][0]*a[1][2])
+a[0][2]*(a[1][0]*a[2][1]-a[2][0]*a[1][1]);
}
void showdata()throws Exception
{
System.out.println("The solution is x,y,z="
+(del1/del)+","+(del2/del)+","+(del3/del));
}
}
Thank you......................
ReplyDeleteNice numerical program.Easy to understand.Thank you very much sir.........
ReplyDelete