Tweet
// Gauss Elimination Method
#include<stdio.h>
main()
{
int n,i,j,k;
float a[20][20],x[20],m,s=0.0;
printf("\nProgram to implement Gauss Elimination Method : \n");
printf("\nEnter the rank of the co-efficient matrix : ");
scanf("%d",&n);
printf("\nEnter the element of the augmented matrix row-wise : ");
for(i=1;i<=n;i++)
for(j=1;j<=n+1;j++)
scanf("%f",&a[i][j]);
for(i=1;i<=n-1;i++)
for(j=i+1;j<=n;j++)
{
m=a[j][i]/a[i][i];
for(k=1;k<=n+1;k++)
a[j][k]=a[j][k]-m*a[i][k];
}
printf("\nThe upper traingular matrix : \n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
printf("%4.3f\t",a[i][j]);
printf("\n");
}
x[n]=a[n][n+1]/a[n][n];
for(i=n-1;i>=1;i--)
{
s=0.0;
for(j=i+1;j<=n;j++)
s=s+a[i][j]*x[j];
x[i]=(a[i][n+1]-s)/a[i][i];
}
printf("\nThe required soln is : \n");
for(i=1;i<=n;i++)
printf("x[%d] = %4.3f\n",i,x[i]);
}
Gauss - Elimination Method in C
Posted by
LAHAUL SETH
~
Gauss - Elimination Method in C
2011-12-23T08:50:00+05:30
LAHAUL SETH
Numerical Methods
|
Programming in C
|
Comments
Gauss - Elimination Method in C
2011-12-23T08:50:00+05:30
LAHAUL SETH
Numerical Methods
|
Programming in C
|