0% found this document useful (1 vote)
234 views2 pages

C Program For Gauss Elimination Method

This C program uses Gauss elimination method to solve a system of linear equations. It takes the number of variables as input, then takes the coefficients and constants of each equation as input and stores them in a 2D array. It then calls the solution function which implements Gauss elimination on the array to calculate the solutions. It prints the solutions by dividing the constant term by the coefficient for each variable.

Uploaded by

chika
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
234 views2 pages

C Program For Gauss Elimination Method

This C program uses Gauss elimination method to solve a system of linear equations. It takes the number of variables as input, then takes the coefficients and constants of each equation as input and stores them in a 2D array. It then calls the solution function which implements Gauss elimination on the array to calculate the solutions. It prints the solutions by dividing the constant term by the coefficient for each variable.

Uploaded by

chika
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<stdio.

h>

void solution( int a[][20], int var );

int main()

int a[ 20 ][ 20 ], var, i, j, k, l, n;

printf("\nA Program to Calculate the Roots of A Sysytem of Linear Equations using Gauss Elimination
Method\n");

printf( "\nEnter the number of variables:\n" );

scanf( "%d", &var );

for ( i = 0;i < var;i++ )

printf( "\nEnter the equation%d:\n", i + 1 );

for ( j = 0;j < var;j++ )

printf( "Enter the coefficient of x%d:\n", j + 1 );

scanf( "%d", &a[ i ][ j ] );

printf( "\nEnter the constant:\n" );

scanf( "%d", &a[ i ][ var] );

solution( a, var );

return 0;

}
void solution( int a[ 20 ][ 20 ], int var )

int k, i, l, j;

for ( k = 0;k < var;k++ )

for ( i = 0;i <= var;i++ )

l = a[ i ][ k ];

for ( j = 0;j <= var;j++ )

if ( i != k )

a[i][j] = (a[k][k]*a[i][j])-(l*a[k][j]);

printf( "\nSolutions:" );

for ( i = 0;i < var;i++ )

printf( "\nTHE VALUE OF x%d IS %f\n", i + 1, ( float ) a[ i ][ var ] / ( float ) a[ i ][ i ] );

You might also like