Numerical Program

Gauss Jordan Method in C

The Gauss-Jordan elimination method to solve a system of linear equations is described in the following steps. 1. Write the augmented matrix of the system. 2. Use row operations to transform the augmented matrix in the form described below, which is called the reduced row echelon form (RREF).

Program of Gauss Jordan in C language

   #include<stdio.h>
   #include<conio.h>
   void main()
  {
    float a[3][4],t; int i,j,k;
    clrscr();
    printf("Enter the elements in row-wise : \n");
    for(i=0;i<3;i++)
    {
        for(j=0;j<4;j++)
        {
            printf("a[%d][%d] : ",i,j);
            scanf("%f",&a[i][j]);
        }
    }
    for(i=0;i<3;i++)
    { for(j=0;j<4;j++)
        {
            printf("%.0f ",a[i][j]);
        }
        printf("\n");
    }
    printf("\n\n");
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            if(i!=j)
            {
                t=a[j][i]/a[i][i];
                for(k=0;k<4;k++)
                a[j][k]=a[j][k]-(a[i][k]*t);
            }
        }
    }
    printf("In Matrix form : \n");
    for(i=0;i<3;i++)
    {
        for(j=0;j<4;j++)
        {
            printf("\t %.0f",a[i][j]);
        }
        printf("\n");
    }
    printf("\n\nSolution is = ");
    for(i=0;i<3;i++)
    {
        printf("%f ",a[i][3]/a[i][i]);
    }   
    
    getch();
    }

Output

Post Your Comment

Some Useful Tricks of Windows

Follow us on Facebook

Advertisement