# C Program for Gauss Elimination Method to Solve Linear Equations

Updated on May 4, 2012 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,c,x;`
`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 . :)

0 of 8192 characters used
• smit

4 years ago

thank to u....

• jnaneshwari

4 years ago

Thank you very much

• koushik

4 years ago

tkx brother

• HY

5 years ago

What do "elements", "constants" mean there?

• shuvo

5 years ago

its Good

• Bhoboghure Omi

5 years ago from Dhaka, Bangladesh

Is it Gauss Naïve or Gauss Jordan method?

• Santanu

5 years ago

Thanks .........

• polska

5 years ago

thank you! you are good!

• polska

5 years ago

you are so luvky

• Shalini

6 years ago

Plz provide a code for Gauss Elimination with partial pivoting. thanks

working