Write a program to demonstrate Gauss Jordan Method in C language.

Tested on: Turbo C++ Version 4.0Time Complexity: O (n3)Space Complexity: O (n2)Open Source: MIT
1
2
            
3
    /* Program to excute Gauss Jordan method*/
4
    #include <stdio.h>
5
    #include <conio.h>
6
    #define max 10
7
    void main()
8
    {
9
        int i, j, k, n;
10
        float a[max][max + 1], x[max], d;
11
        printf("Enter the number of equations\n");
12
        scanf("%d", &n);
13
        printf("Enter augmented matrix rowwise\n");
14
        for (i = 0; i < n; i++)
15
        {
16
            for (j = 0; j < n + 1; j++)
17
            {
18
                scanf("%f", &a[i][j]);
19
            }
20
        }
21
        for (j = 0; j < n; j++)
22
        {
23
            for (i = 0; i < n; i++)
24
            {
25
                if (i != j)
26
                {
27
                    d = a[i][j] / a[j][j];
28
                    for (k = 0; k < n + 1; k++)
29
                    {
30
                        a[i][j] = a[j][j] - a[j][k] * d;
31
                    }
32
                }
33
            }
34
        }
35
        printf("The solution of given systme is\n");
36
        for (i = 0; i < n; i++)
37
        {
38
            x[i] = a[i][n] / a[i][i];
39
            printf("x[i] = %f", x[i]);
40
        }
41
    }
42
            
43
            

Output

1
2
Output not available.
3
            
4
            

Rate the Code

Reviews are published after a quick safety check (usually within 24 hours).

Reviews are public. Developers can see basic device specifications to respond. Learn more

How to run Gauss Jordan Method program in C-Language?

To run Gauss Jordan Method program in C-Language, follow the below mentioned steps:

  1. Copy the Code: Press the copy button in the code block to copy the complete code.
  2. Open Turbo C++ Version 4: Open the Turbo C++ (Version 4) software on your system.
  3. Paste the code: Paste the copied code into Turbo C++’s editor.
  4. Compile the Code: Compile the program by pressing the Alt+F9 keys. This shows you the errors and warnings, if any.
  5. Run the code: Press the Ctrl+F9 keys to run the program if the program is successfully compiled.
  6. Enter the Input: Provide the required inputs or your desired inputs, if applicable.
  7. Receive the Result: Get the result of the program on the screen based on the provided inputs.

More about the Gauss-Jordan Method

Discovered by: Wilhelm Jordan

Discovered Year: 1888

This method is based on the method of Carl Friedrich Gauss, a mathematician.

The Gauss-Jordan method is the advanced version of the Gauss Elimination method. In this method, the operations are applied to the matrix of the linear equations (Ax=b).

How does the Gauss-Jordan method work?

  • The main purpose of the Gauss-Jordan method is to find the values of the linear equations by converting the system of equations into the matrix known as the augmented matrix.
  • Then the augmented matrix is converted into the Identity Matrix, which contains 1 at the diagonal and the rest of the elements are 0.
  • By solving the Identity Matrix, the answer is calculated.

Difference between Gauss Elimination and Gauss-Jordan Methods

Gauss EliminationGauss-Jordan Method
The upper triangular matrix will be zero, and at last, with the help of back-substitution, the solution is calculated.First, the matrix is converted into Reduced Row Echelon Form (RREF), which means an identity matrix, to find the variable values by solving the matrix

Where to use the Gauss-Jordan Method?

To find out the inverse of a matrix or want to get exact solution of equation instantly, the Gauss-Jordan method is used.

Real-life Applications of Gauss-Jordan Method

  1. Matrix Inversion: To get the matrix inversion in computer graphics, cryptography, and advanced engineering calculations.
  2. Linear Programming (Operations Research): The basis of the Gauss-Jordan method is used in business and supply chain operations.
  3. Economics & Input – Output Models: To balance the financial resources in the different sectors.

Limitations of Gauss-Jordan Method

  1. Slow Speed: It performs about 50% more calculations than Gauss Elimination, so it takes more time.
  2. Computer Memory and Round-Off: If the matrices are very big with thousands of variables, then computer memory management is a big challenge, and round-off error occurs in the calculations.

Alternate Methods

  1. Standard Gauss Elimination + Back-Substitution: In equation solving, the standard Gauss elimination is much faster than the Gauss-Jordan method because it only zeros out the elements above the diagonal.
  2. LU Decomposition: To solve the same matrix with different values, LU Decomposition is more efficient.
License: This program's source code is open-sourced under the MIT License, while the rest of the program's text content and overall dhimanp platform and brand content remain proprietary under dhimanp.

Submit your modified code

Your submissions are published after a quick safety check (usually within 7 days).

Submissions are public. Developers can see basic device specifications to respond. Learn more

Disclaimer

The information that you shared with us will be publicly visible, and everyone can see your information. And we (dhimanp) are not responsible if anyone misuses this information. We can remove any submitted code at any time for better transparency.

Privacy Policy

If you share your data with us by submitting your code for credit, then we may show your full name, school or college name, and city name on our website.

We are not using this data to track you and are not selling this data to anyone.

If you want to remove your name from our website, you can contact us, and we will remove your name from our website. In the removal process, full credit, including your full name, school or college, city, and code, will be removed from our website.