Gaussian Elimination Method
Give ur comments
#include
#include
#include
void main()
{
float x[5][5],r1[4],r2[4],r3[4];
float a,b,c;
int i,j,k;
clrscr();
printf("\n\t\t GAUSS ELIMINATION METHOD");
printf("\n\t\t==========================\n");
for(i=1;i<=3;i++)
{
printf("\n --**:: EQUATION No. : %d ::**--",i);
printf("\n --------------------------------");
for(j=1;j<=4;j++)
{
printf("\nCoeficient of %d term : ",j);
scanf("%f",&x[i][j]);
}
}
/*STEP ONE */
for(k=0;k<4;k++)
{
r1[k]=x[1][k+1]*x[2][1];
r2[k]=x[2][k+1]*x[1][1];
r2[k]=r2[k]-r1[k];
}
for(k=0;k<4;k++)
{
r1[k]=x[1][k+1]*x[3][1];
r3[k]=x[3][k+1]*x[1][1];
r3[k]-=r1[k];
}
for(k=1;k<=4;k++)
{
x[2][k]=r2[k-1];
x[3][k]=r3[k-1];
}
/*STEP TWO*/
for(k=0;k<4;k++)
{
r2[k]=x[2][k+1]*x[3][2];
r3[k]=x[3][k+1]*x[2][2];
r3[k]-=r2[k];
}
for(k=1;k<=4;k++)
x[3][k]=r3[k-1];
/*STEP 3 BACK SUBSTITUION*/
c=x[3][4]/x[3][3];
b=(x[2][4]-c*x[2][3])/x[2][2];
a=(x[1][4]-b*x[1][2]-c*x[1][3])/x[1][1];
printf("\n===================================\n");
printf("\n Solution is : \n");
printf("\n X = %6.3f\t Y = %6.3f\t Z = %6.3f",a,b,c);
getch();
}
OUTPUT
Hey thanks for the program... Its really working...
ReplyDelete