You are on page 1of 4

/*Ate Nena*/

/*Gauss - Jordan method*/


#include<stdio.h>
#include<stdlib.h>

double a[3][4];

void gauss_jordon()

/*converts the matrix A into Identity Matrix*/

{
int i,j,k;
double factor,pivot;

for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(j!=i)
{
pivot=a[i][i];
factor=a[j][i];
for(k=0;k<4;k++)
{
a[i][k]=a[i][k]/pivot;
a[j][k]=a[j][k]- (factor*a[i][k]);
}
}
}
}

int main()
{
int i,j;

printf("\nEnter the matrix A :\n"); /*Matrix A contains the coefficients of the equations*/
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("\nEnter element a[%d][%d] : ",i+1,j+1);
scanf("%lf",&a[i][j]);
}
}
system("cls");
printf("\nEnter the matrix B :\n");

for(i=0,j=3;i<3;i++) /*Matrix B contains the right hand side constants of the equations*/
{
printf("\nEnter element b[%d][1] : ",i+1);
scanf("%lf",&a[i][j]);
}
system("cls");

printf("\nThe Augmented Matrix [ A : B ] formed is as shown :\n");


for(i=0;i<3;i++)

{
for(j=0;j<4;j++)
{
printf("\t%lf",a[i][j]);
}
printf("\n");
}

printf("\n\nPress Enter\n");
getch();
system("cls");

gauss_jordon();

printf("\nMatrix after Eliminaton :\n");


for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
printf("\t%lf",a[i][j]);
printf("\n");
}

printf("\nSolution :\n");
for(i=120,j=0;i<123;i++,j++)
{
printf("\n%c : %lf",i,a[j][3]);
}

return 0;

You might also like