#include <stdio.h>
#include <conio.h>
int main()
{
/* DEFINE PARAMETER*/
int i,j,k,f,n ;
float a[100][100],b[100];
printf("\n\n\t << this program obtain solutions of problem with Gauss_Jordan >>");
printf("\n\nenter degree of equation :");
scanf ("%d",&n);
for (i=0 ; i<n ; i++)
{
printf("\nenter coefficient of equation %d ...\n",i+1);
for (j=0; j<n ; j++)
{
printf("a[%d][%d]=",i+1,j+1);
scanf("%f",&a[i][j]);
}
}
printf("\nenter reply of equation ...\n");
for (i=0;i<n;i++)
{
printf("b[%d]=",i);
scanf("%f",&b[i]);
}
//printf("****%d*****\n",n);
for(i=0;i<n;i++)
a[i][n]=b[i];
printf("\n you entered :\n");
for (i=0;i<n;i++)
{
for(j=0;j<n+1;j++)
{
printf("%.1f",a[i][j]);
printf("\t");
}
printf("\n");
}
for (i=0 ; i<n ; i++)
{
for(j=0 ; j<n+1 ; j++)
{
if (j!=i)
a[i][j]=a[i][j]/a[i][i];
}
a[i][i]=1;
for( f=0 ; f<n ; f++)
{
for( k=i ; k<n+1 ; k++)
{
if (( f!=i) && (k!=i))
a[f][k]=a[f][k]-(a[f][i]*a[i][k]);
}
if (i!=f)
a[f][i]=0;
}
}
printf("\n\nmatrix of Gauss_Jordan is:\n");
for (i=0;i<n;i++)
{
for(j=0;j<n+1;j++)
{
printf("%.1f",a[i][j]);
printf("\t");
}
printf("\n");
}
printf("\n\n** result of this equation is: **\n\n");
for (i=0;i<n;i++)
printf("x%d = %.1f\n",i,a[i][n]);
getch();
return 0;
}