0% found this document useful (0 votes)
23 views3 pages

Gauss Elimination Method

This document describes the Gauss elimination method for solving systems of linear equations. It includes the C code to implement the Gauss elimination approach. The code first takes the number of unknowns as input, then collects the coefficients and constants of the system of equations. It then performs Gauss elimination by eliminating variables one by one to obtain an upper triangular system of equations that can be easily solved for the unknowns. Finally, the code prints out the solution values for each unknown.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views3 pages

Gauss Elimination Method

This document describes the Gauss elimination method for solving systems of linear equations. It includes the C code to implement the Gauss elimination approach. The code first takes the number of unknowns as input, then collects the coefficients and constants of the system of equations. It then performs Gauss elimination by eliminating variables one by one to obtain an upper triangular system of equations that can be easily solved for the unknowns. Finally, the code prints out the solution values for each unknown.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

GAUSS ELIMINATION APPROACH

#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int i,j,k,n;
float a[20][20],x[20],c[20];
printf("\n GAUSS ELIMINATION METHOD");
printf("\n Enter the number of unknowns:\n");
scanf("%d",&n);
printf("\n Enter the Constants:\n");
for (i=0;i<n;i++)
scanf("%f",&c[i]);
printf("\n Enter the coefficients :\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("\n a[%d][%d]=",i,j);
scanf("%f",&a[i][j]);
}
}

for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("\t%f",a[i][j]);
}
printf("\t%f",c[i]);
printf("\n");
}
for(k=0;k<n-1;k++)
{
for(i=k+1;i<n;i++)
{
for(j=k+1;j<n;j++)
a[i][j]=a[i][j]-(a[i][k]/a[k][k])*a[k][j];
c[i]=c[i]-(a[i][k]/a[k][k])*c[k];
}
}
x[n-1]=c[n-1]/a[n-1][n-1];
printf("\nThe solution is:\n");
printf("x[%d]=%f\n",n-1,x[n-1]);
for(k=0;k<n-1;k++)
{

i=n-k-2;
for(j=i+1;j<n;j++)
c[i]=c[i]-(a[i][j]*x[j]);
x[i]=c[i]/a[i][i];
printf("x[%d]=%f\n",i,x[i]);
}
getch();
}

You might also like