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

13y ago

Still curious? Ask our experts.

Chat with our AI personalities

JordanJordan
Looking for a career mentor? I've seen my fair share of shake-ups.
Chat with Jordan
DevinDevin
I've poured enough drinks to know that people don't always want advice—they just want to talk.
Chat with Devin
RafaRafa
There's no fun in playing it safe. Why not try something a little unhinged?
Chat with Rafa

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