answersLogoWhite

0

#include<stdio.h>

#include<stdlib.h>

#include<math.h>

#include<conio.h>

void main(void)

{

int K, P, C, J;

double A[100][101];

int N;

int Row[100];

double X[100];

double SUM, M;

int T;

do

{

printf("Please enter number of equations [Not more than %d]\n",100);

scanf("%d", &N);

} while( N > 100);

printf("You say there are %d equations.\n", N);

printf("From AX = B enter elements of [A,B] row by row:\n");

for (K = 1; K <= N; K++)

{

for (J = 1; J <= N+1; J++)

{

printf(" For row %d enter element %d please :\n", K, J);

scanf("%lf", &A[K-1][J-1]);

}

}

for (J = 1; J<= N; J++) Row[J-1] = J - 1;

for (P = 1; P <= N - 1; P++)

{

for (K = P + 1; K <= N; K++)

{

if ( fabs(A[Row[K-1]][P-1]) > fabs(A[Row[P-1]][P-1]) )

{

T = Row[P-1];

Row[P-1] = Row[K-1];

Row[K-1] = T;

}

}

if (A[Row[P-1]][P-1] 0)

{

printf("The matrix is SINGULAR !\n");

printf("Cannot use algorithm --- exit\n");

exit(1);

}

X[N-1] = A[Row[N-1]][N] / A[Row[N-1]][N-1];

for (K = N - 1; K >= 1; K--)

{

SUM = 0;

for (C = K + 1; C <= N; C++)

{

SUM += A[Row[K-1]][C-1] * X[C-1];

}

X[K-1] = ( A[Row[K-1]][N] - SUM) / A[Row[K-1]][K-1];

}

for( K = 1; K <= N; K++)

printf("X[%d] = %lf\n", K, X[K-1]);

getch();

}

User Avatar

Wiki User

14y 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
SteveSteve
Knowledge is a journey, you know? We'll get there.
Chat with Steve
JudyJudy
Simplicity is my specialty.
Chat with Judy

Add your answer:

Earn +20 pts
Q: Gaussian elimination in c
Write your answer...
Submit
Still have questions?
magnify glass
imp