answersLogoWhite

0

#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;

}

}

User Avatar

Wiki User

12y ago

Still curious? Ask our experts.

Chat with our AI personalities

MaxineMaxine
I respect you enough to keep it real.
Chat with Maxine
RossRoss
Every question is just a happy little opportunity.
Chat with Ross
BeauBeau
You're doing better than you think!
Chat with Beau

Add your answer:

Earn +20 pts
Q: C program for gauss elimination method to solve linear algebraic equations?
Write your answer...
Submit
Still have questions?
magnify glass
imp