# Gauss Jordan Method in C

In this article, we will discuss the gauss Jordan method with its examples.

## Introduction:

The Gauss-Jordan method is also known as the Gauss-Jordan elimination method. It is a modified version of the Gauss Elimination Method used to solve a system of linear equations.

It is comparable to and easier than the Gauss Elimination Method because the latter requires the performance of two distinct processes, i.e.

• Upper triangular matrix formation
• Back replacement

However, in the case of the Gauss-Jordan Elimination Method, we just need to create a diagonal matrix with a reduced row echelon form.

Example of the Gauss-Jordan method for solving a system of linear equations:

Input:

3x - 2y + z = 7

x + y + z = 2

2x - y - 3z = 1

Output:

Final Augmented Matrix is:

1 0 0 1

0 1 0 2

0 0 1 3

Result is: x = 1, y = 2, z = 3

Explanation:

In this example, we conduct row operations to change the augmented matrix into row-column form and then further transform it into reduced row-column form to solve this system of equations using the Gauss-Jordan method. The matrix's final form enables us to immediately read out the answers for x, y, and z.

The following row operations were utilised to convert the augmented matrix into its final state:

Row2 = Row2 - 3 * Row1

Row3 = Row3 - 2 * Row1

Row1 = Row1 + Row2

Row3 = Row3 + Row2

Row1 = Row1 - 3 * Row3

Row2 = Row2 - 2 * Row3

These row operations result in the final augmented matrix that is displayed in the output. The values of x, y, and z, which are 1, 2, and 3, are shown in the last column of the matrix.

Here is the C program's source code for solving a system of linear equations. The system successfully compiles the C program. Also presented below is the output of the program.

### Code:

Output:

```Testcase Input:
Enter the number of variables: 4

Enter the equation1:
Enter the coefficient of x1: 2
Enter the coefficient of x2: 1
Enter the coefficient of x3: -3
Enter the coefficient of x4: 4
Enter the constant: 9

Enter the equation2:
Enter the coefficient of x1: 1
Enter the coefficient of x2: -2
Enter the coefficient of x3: 4
Enter the coefficient of x4: 3
Enter the constant: 7

Enter the equation3:
Enter the coefficient of x1: 3
Enter the coefficient of x2: 1
Enter the coefficient of x3: 5
Enter the coefficient of x4: -2
Enter the constant: 4

Enter the equation4:
Enter the coefficient of x1: 2
Enter the coefficient of x2: -5
Enter the coefficient of x3: 2
Enter the coefficient of x4: 1
Enter the constant: -6

Solutions:
THE VALUE OF x1 IS 1.000000
THE VALUE OF x2 IS 2.000000
THE VALUE OF x3 IS 3.000000
THE VALUE OF x4 IS -1.000000
```

Explanation:

The input represents the following system of linear equations:

2x1 + x2 - 3x3 + 4x4 = 9

x1 - 2x2 + 4x3 + 3x4 = 7

3x1 + x2 + 5x3 - 2x4 = 4

2x1 - 5x2 + 2x3 + x4 = -6

The Gauss-Jordan method is used by the program to solve the system of equations, and it outputs the values 1.000000, 2.000000, 3.000000, and -1.000000 for x1, x2, and x3, accordingly. These numbers are the system's solution because they fulfil all four equations. It is the complete explanation of the Gauss-Jordan method.