Using the Gauss Jordan End approach write C program.

Question

Help me with a C program that executes the Gauss Jordan End approach.

Summary

A system of linear equations is used in the first question, and the equations are solved using the Gauss Jordan End approach, with the results presented on the console.

Explanation

In this question, the solution method is used, which accepts a two-dimensional array and its size as input.
The coefficients of each linear equation in the system of linear equations are stored in each row of the array.

The solution to the ‘n’ number of linear equations is then found using three loops.

The procedure then prints the system of equations solution, that is, the variables are discovered and displayed.
The user enters the number of equations initially, and then the coefficients of each linear equation are found and stored in an array in the main procedure.

The array and its size are then supplied to the solution function, and the equations are solved this way solved using the Gauss Jordan.

Code

#include<stdio.h> 
void solution(int a[20][20], int p)
{
    for (int i=0;i<p;i++ ){
        for (int m=0;m<=p;m++ ){
            int l=a[m][i];
            for (int j=0;j<=p;j++ ){
                if(m!=i)
                a[m][j]=(arr[i][i]*arr[m][j])-(l*arr[i][j]);
            }
        }
    }
    printf("\nSOLUTION:\n");
    for(int m=0;m<p;m++){
        printf("\nThe value of x%d is %f\n",(m+1), 
        (float)arr[m][p]/(float)arr[m][m]);
    }
}
int main()
{
    int n;
    printf("Enter number of variables: ");
    scanf("%d",&n);
    int a[20][20];
    for (int i = 0;i<n;i++ ){
        printf( "\nEnter the equation %d:\n",i+1);
        for (int j=0;j<num;j++){
            printf( "Enter the coefficient x%d: ",j+1);
            scanf("%d",&arr[i][j]);
        }
        printf("Enter constant: ");
        scanf("%d",&arr[i][n]);
    }
    solution(a,n);
    return 0;
}

Output

Gauss Jordan End approach

 

Also read, Can you fix any mistake on this C program

 

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *