0% found this document useful (0 votes)
30 views2 pages

C Program For Gauss Elimination Method To Solve Linear Equations

C Program for Gauss Elimination Method to Solve Linear Equations

Uploaded by

SubhashisGhosh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views2 pages

C Program For Gauss Elimination Method To Solve Linear Equations

C Program for Gauss Elimination Method to Solve Linear Equations

Uploaded by

SubhashisGhosh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

11/13/2014

C Program for Gauss Elimination Method to Solve Linear Equations

C Program for Gauss Elimination Method


to Solve Linear Equations

by techniche
11 Followers

We all know that Gauss elimintaion method used in mathematics is easier to find
the solution of linear equations . Following is the source code for the same method
. Just copy the code in your notepad and save it with the extension *.c or *.cpp.
Then open the saved file with your Compiler and run it .
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,k,n;
float a[10][10],c[10],x[10];
printf("****** welcome 2 gauss elimination method *******\n");
printf("\nenter the number of elements: ");
scanf("%d",&n);
printf("Enter constants: ");
for(i=0;i<n;i++)
scanf("%f",&c[i]);
printf("\nenter the matrix: ");
for(i=0;i<n;i++){
for(j=0;j<n;j++)
scanf("%f",&a[i][j]);
}
for(k=0;k<n-1;i++){
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("The 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();
}
}

After running the program , you need to enter the constants as well as coefficient
of the three linear equations in the form of matrix . The program thereafter will give
you desired result . :)
Last updated on May 4, 2012

http://techniche.hubpages.com/hub/C-Program-for-Gauss-Elimination-Method-To-Solve-Linear-Equations

1/2

11/13/2014

C Program for Gauss Elimination Method to Solve Linear Equations

http://techniche.hubpages.com/hub/C-Program-for-Gauss-Elimination-Method-To-Solve-Linear-Equations

2/2

You might also like