-
Notifications
You must be signed in to change notification settings - Fork 22
/
gaussjordan-elimination
56 lines (42 loc) · 1.09 KB
/
gaussjordan-elimination
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include<stdio.h>
void solution( int a[][20], int var );
int main()
{
int a[ 20 ][ 20 ], var, i, j, k, l, 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 ] );
}
}