Sunday, December 12, 2010

Jordan Elimination Method

//PROGRAM TO FIND SOLUTION TO LINEAR EQAUTIONS USING JORDAN ELIMINATION.

#include
#include
void solution(int a[20][20],int n);
void main()
{
int a[20][20],n,i,j,k,l;
clrscr();
printf("\n-------Jordan Elimination method----------");
printf("\nEnter the number of variables:\n");
scanf("%d",&n);
for(i=0;i {
printf("\nEnter the equation%d\n",i+1);
for(j=0;j {
printf("Enter the coefficient of x%d:",j+1);
scanf("%d",&a[i][j]);
}
printf("\nEnter the constant:");
scanf("%d",&a[i][n]);
}
solution(a,n);
getch();
}

void solution(int a[20][20],int n)
{
int k,i,l,j;
for(k=0;k {
for(i=0;i<=n;i++)
{
l=a[i][k];
for(j=0;j<=n;j++)
{
if(i!=k)
a[i][j]=a[k][k]*a[i][j]-l*a[k][j];
}
}
}
printf("\n---------Solution----------");
for(i=0;i {
printf("\nThe value of x%d is %f\n",i+1,(float)a[i][n]/(float)a[i][i]);
}
}

Output
-----------------------------------------

-------Jordan Elimination method----------
Enter the number of variables:
2

Enter the equation1
Enter the coefficient of x1:2
Enter the coefficient of x2:2

Enter the constant:4

Enter the equation2
Enter the coefficient of x1:1
Enter the coefficient of x2:3

Enter the constant:4

---------Solution----------
The value of x1 is 1.000000

The value of x2 is 1.000000

No comments:

Post a Comment