This C program implements iterative version of Gauss Seidel Method. In this method, a system of linear equations is solved by iteration, using a brute-force kind of technique, to reach the actual solution.

Here is the source code of the C program to solve a system of linear equations. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

`#include <stdio.h>`

int main() {

`//a sparse way of representing the equations`

float eq[3][4];

int i;

float x ,y , z;

x = 1; y = 1; z = 2; //initial guess

eq[0][0] = 7/4.0;

eq[0][1] = 0;

eq[0][2] = 1/4.0;

eq[0][3]= -1/4.0;

eq[1][0] = 21/8.0;

eq[1][1] = 4/8.0;

eq[1][2] = 0;

eq[1][3]= 1/8.0;

eq[2][0] = 15/5.0;

eq[2][1] = 2/5.0;

eq[2][2] = -1/5.0;

eq[2][3]= 0;

`//10 iterations of gauss-seidel`

for (i = 0;i < 10; i++) {

x = eq[0][0] + eq[0][2] * y + eq[0][3] * z;

y = eq[1][0] + eq[1][1] * x + eq[1][3] * z;

z = eq[2][0] + eq[2][1] * x + eq[2][2] * y;

printf("Output: \n%f %f %f\n", x, y, z);

`}`

return 0;

`}`

$ gcc gauss_seidel.c -o gauss_seidel $ ./gauss_seidel 1.500000 3.625000 2.875000 1.937500 3.953125 2.984375 1.992188 3.994141 2.998047 1.999023 3.999268 2.999756 1.999878 3.999908 2.999969 1.999985 3.999989 2.999996 1.999998 3.999999 3.000000 2.000000 4.000000 3.000000 2.000000 4.000000 3.000000 2.000000 4.000000 3.000000

**Sanfoundry Global Education & Learning Series – 1000 C Programs.**

Here’s the list of Best Reference Books in C Programming, Data Structures and Algorithms.