Search:

Submit Article

# GUASS ELIMINATION METHOD

Posted By: Adalbert Fischer     Category: C Programming     Views: 40822

## Code for GUASS 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,j;
clrscr();
printf("\nEnter size of matrix: ");
scanf("%d",&n);
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]);
}

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];
for(i=1,j=0;j<n+1;j++)
{
mat[i+1][j]=mat[i+1][j]-(mat[i][j]*temp);
}

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][2]*z)/mat[1][1];
x = (mat[0][3] - mat[0][2]*z - mat[0][1]*y)/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 eqvationenter the value of coeffcient 1: 2enter the value of coeffcient 2: 1enter the value of coeffcient 3: 1enter the value of constent: 10enter the value of 2 eqvationenter the value of coeffcient 1: 3enter the value of coeffcient 2: 2enter the value of coeffcient 3: 3enter the value of constent: 18enter the value of 3 eqvationenter the value of coeffcient 1: 1enter the value of coeffcient 2: 4enter the value of coeffcient 3: 9enter the value of constent: 16  Your Matrix 2  1  1  10 3  2  3  18 1  4  9  16 2.000  1.000   1.000   10.000 0.000  0.500   1.500   3.000 0.000  0.000  -2.000  -10.000x = 7.000y = -9.000z = 5.000*/```
Share:

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

 Adalbert Fischer author of GUASS ELIMINATION METHOD is from Frankfurt, Germany. View All Articles

 Please enter your CommentComment should be atleast 30 Characters.Please put code inside [Code] your code [/Code]. No Comment Found, Be the First to post comment!