Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Numerical MethodsRSS Feeds

GUASS JORDEN ELIMINATION METHOD

Posted By: Emma Campbell     Category: C Programming     Views: 5393

Write a program of GUASS JORDEN ELIMINATION METHOD.

Code for GUASS JORDEN ELIMINATION METHOD in C Programming

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
  float mat[4][4],temp,temp1,x,y,z;
  int i,n=3,j;
//  clrscr();for(i=0; i<n; i++)
  {
   printf("\n\nenter the value of %d eqvation",i+1);
   for(j=0; j<n; j++)
   {
    printf("\nenter the value of coeffcient %d: ",j+1);
    scanf("%f",&mat[i][j]);
   }
   printf("\nenter the value of constent: ");
   scanf("%f",&mat[i][j]);
  }

  printf("\n* * * Your Matrix * * *\n\n");
  for(i=0;i<n;i++)
  {
   for(j=0;j<n+1;j++)
   {
    printf(" %g ",mat[i][j]);
   }
   printf("\n\n");
  }

  temp=mat[1][0]/mat[0][0];
  temp1=mat[2][0]/mat[0][0];
  for(i=0,j=0;j<n+1;j++)
  {
   mat[i+1][j]=mat[i+1][j]-(mat[i][j]*temp);
   mat[i+2][j]=mat[i+2][j]-(mat[i][j]*temp1);
  }

  temp=mat[2][1]/mat[1][1];
  temp1=mat[0][1]/mat[1][1];
  for(i=1,j=0;j<n+1;j++)
  {
   mat[i+1][j]=mat[i+1][j]-(mat[i][j]*temp);
   mat[i-1][j]=mat[i-1][j]-(mat[i][j]*temp1);
  }


  temp=mat[0][2]/mat[2][2];
  temp1=mat[1][2]/mat[2][2];
  for(i=0,j=0;j<n+1;j++)
  {
   mat[i][j]=mat[i][j]-(mat[i+2][j]*temp);
   mat[i+1][j]=mat[i+1][j]-(mat[i+2][j]*temp1);
  }

  for(i=0;i<n;i++)
  {
   for(j=0;j<n+1;j++)
   {
    printf(" %.3f ",mat[i][j]);
   }
   printf("\n\n");
  }

  z = mat[2][3]/mat[2][2];
  y = mat[1][3]/mat[1][1];
  x = mat[0][3]/mat[0][0];
  printf("\n\nx = %.3f",x);
  printf("\n\ny = %.3f",y);
  printf("\n\nz = %.3f",z);

  getch();
}


/*
______________________________________

OUT PUT
______________________________________



enter the value of 1 eqvation
enter the value of coeffcient 1: 2

enter the value of coeffcient 2: 1

enter the value of coeffcient 3: 1

enter the value of constent: 10


enter the value of 2 eqvation
enter the value of coeffcient 1: 3

enter the value of coeffcient 2: 2

enter the value of coeffcient 3: 3

enter the value of constent: 18


enter the value of 3 eqvation
enter the value of coeffcient 1: 1

enter the value of coeffcient 2: 4

enter the value of coeffcient 3: 9

enter the value of constent: 16

* * * Your Matrix * * *

2 1 1 10

3 2 3 18

1 4 9 16

2.000 0.000 0.000 14.000

0.000 0.500 0.000 -4.500

0.000 0.000 -2.000 -10.000



x = 7.000

y = -9.000

z = 5.000

*/
  
Share: 

 
 
 

Didn't find what you were looking for? Find more on GUASS JORDEN ELIMINATION METHOD Or get search suggestion and latest updates.

Emma Campbell
Emma Campbell author of GUASS JORDEN ELIMINATION METHOD is from Toronto, Canada.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!