Gauss Elimination method in C language using Lower triangular matrix

This is a simple C language program that calculates solution of n-linear equations using Non-pivotal Gauss Elimination method. It uses lower triangular matrix to do so, for upper triangular matrix visit here.

#include<stdio.h>
#include<conio.h>
 
float matrix[10][10], m, temp[10];
int i, j, k, n;
 
void lower_traingularisation() {
    for (i=n-1; i>0; i--)
        for (j=i-1; j>=0; j--) {
            m	= matrix[j][i]/matrix[i][i];
            for (k=0; k<n+1; k++) {
                matrix[j][k]	= matrix[j][k]-(m*matrix[i][k]);
            }
        }
} //lower_traingularisation
 
void back_subsitution() {
    for (i=0; i<n; i++) {
        m	= matrix[i][n];
        for (j=0; j<i; j++)
            m	= m - temp[j] * matrix[i][j];
        temp[i]	= m/matrix[i][i];
        printf("\n x%d => %f", i+1, temp[i]);
    }
} // back_subsitution
 
void main() {
    printf("Enter number. of variables :: ");
    scanf("%d", &n);
 
    printf("Enter the augmented matrix: \n");
    for (i=0; i<n; i++)
        for (j=0; j<n+1; j++)
            scanf("%f", &matrix[i][j]);
 
    lower_traingularisation();
 
    printf("The lower traingular matrix is : \n");
 
    for (i=0; i<n; i++) {
        for (j=0; j<n+1; j++)
            printf("%f \t", matrix[i][j]);
        printf("\n");
    }
 
    printf("The required result is : \n");
 
    back_subsitution();
 
    getch();
} // main

Gauss Elimination method for solving n-linear equations in C language

This is a simple C language program that calculates solution of n-linear equations using Non-pivotal Gauss Elimination method. It uses upper triangular matrix to do so, for solution using lower triangular matrix visit here.

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
#include<stdio.h>
#include<conio.h>
 
float matrix[10][10], m, temp[10];
int i, j, k, n;
 
void upper_triangularization() {
	for (i=0; i<n-1; i++)
		for (j=i+1; j<n; j++) {
			m	= matrix[j][i]/matrix[i][i];
			for (k=0; k<n+1; k++) {
				matrix[j][k]	= matrix[j][k]-(m*matrix[i][k]);
			}
		}
} //upper_traingulisation
 
void back_subsitution() {
	for (i=n-1; i>=0; i--) {
		m	= matrix[i][n];
		for (j=n-1; j>i; j--)
			m	= m - temp[n-j] * matrix[i][j];
		temp[n-i]	= m/matrix[i][i];
		printf("\n x%d => %f", i+1, temp[n-i]);
	}
} // back_subsitution
 
void main() {
	printf("Enter number. of variables :: ");
	scanf("%d", &n);
 
	printf("Enter the augmented matrix: \n");
	for (i=0; i<n; i++)
		for (j=0; j<n+1; j++)
			scanf("%f", &matrix[i][j]);
 
	upper_triangularization();
 
	printf("The upper traingular matrix is : \n");
 
	for (i=0; i<n; i++) {
		for (j=0; j<n+1; j++)
			printf("%f \t", matrix[i][j]);
		printf("\n");
	}
 
	printf("The required result is : \n");
 
	back_subsitution();
 
	getch();
} // main