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
Follow me
Latest posts by Abhishek Gupta (see all)

Leave a Reply