Resources » Articles/Knowledge Sharing » General

C Program - Application of gauss elimination method


Posted Date: 14-Oct-2007  Last Updated:   Category: General    
Author: Member Level: Gold    Points: 2


A C program to find out the unknown value of x, y, z using Gauss elimination method.



/*Objective :To find out the unknowns (x,y,z) using Gauss elimination method*/

#include"stdio.h"
#include"conio.h"
#include"math.h"
void main()
{
int i,j;
float a[3][4],b[3][4],c[4][4];
float x,y,z,p,q,r;
m:
printf("\nEnter the coefficients: ");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("%f",&a[i][j]);
printf("\nEnter the constants: ");
for(i=0;i<3;i++)
scanf("%f",&a[i][3]);

if(a[0][0]!=0.0)
{
p=a[1][0];
q=a[0][0];
r=a[2][0];
for(j=0;j<=3;j++)
{
b[0][j]=-(p/q)*a[0][j];
a[1][j]+=b[0][j];
c[0][j]=-(r/q)*a[0][j];
a[2][j]+=c[0][j];
}
p=a[2][1];
q=a[1][1];
for(j=0;j<=3;j++)
{
b[1][j]=-(p/q)*a[1][j];
a[2][j]+=b[1][j];
}
printf("\n\nThe matrix becomes\n");
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
printf("%.4f\t",a[i][j]
}
printf("\n");
}
z=a[2][3]/a[2][2];
y=(a[1][3]-a[1][2]*z)/a[1][1];
x=(a[0][3]-a[0][2]*z-a[0][1]*y)/a[0][0];
printf("\nThe solution is");
printf("\nX=%f, Y=%f , Z=%f",x,y,z);
}
else
{
printf("\nThe first cofficient must not be zero,Enter again");
goto m;
}
}


Read related articles: Gauss Elimination    

Did you like this resource? Share it with your friends and show your love!




Responses to "C Program - Application of gauss elimination method"
Author: Lenin    06 Jun 2008Member Level: Gold   Points : 2
I like your active participation in 2007; but y u r not involving much in 2008, as i am not frequently finding any posts;
can you share what happened here?
Any problem.
Feel free to say , as this may be a direction for us shape our future

BEst regards,
Lenin



Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Submit Article     Return to Article Index

    Awards & Gifts
    Active Members
    TodayLast 7 Daysmore...

    ISC Technologies, Kochi - India. Copyright © All Rights Reserved.