ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

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[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 . :)

Comments

    0 of 8192 characters used
    Post Comment

    • profile image

      Shalini 5 years ago

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

    • profile image

      polska 4 years ago

      you are so luvky

    • profile image

      polska 4 years ago

      thank you! you are good!

    • profile image

      Santanu 3 years ago

      Thanks .........

    • Bhoboghure Omi profile image

      Bhoboghure Omi 3 years ago from Dhaka, Bangladesh

      Is it Gauss Naïve or Gauss Jordan method?

    • profile image

      shuvo 3 years ago

      its Good

    • profile image

      HY 3 years ago

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

    • profile image

      koushik 2 years ago

      tkx brother

    • profile image

      jnaneshwari 2 years ago

      Thank you very much

    • profile image

      smit 2 years ago

      thank to u....

    Click to Rate This Article