Thursday 14 June 2012

Program to find simultaneous linear equations using Jordan Elimination method

/*
#include<stdio.h>
#include<stdlib.h>
main()
{
int a[10][10],n,i,j,k;
printf("\n\tEnter the no.of variables: ");
scanf("%d", &n);
for(i=0;i<n;i++)
{
printf("\n\tEQUATION %d\n\t", i+1);
for(j=0;j<n;j++)
{
printf("\n\tEnter the coefficients of x%d : ", j+1);
scanf("%d", &a[i][j]);
}
printf("\nEnter the constant: ");
scanf("%d", &a[i][n]);
}
for(k=0;k<n;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\tSolutions are: \n");
for(i=0;i<n;i++)
{
if(a[i][i]==0)
{
printf("\n\tNOn trivial solution");
exit(0);
}
printf("\n\tThe value of %d
is %.3f",i+1,(float)(a[i][n]/(float)a[i][i]));
}
}

/*
-----------------OUTPUT------------------------

Enter the no.of variables: 3

EQUATION 1

Enter the coefficients of x1 : 3

Enter the coefficients of x2 : 2

Enter the coefficients of x3 : 1

Enter the constant: 6

EQUATION 2

Enter the coefficients of x1 : 1

Enter the coefficients of x2 : 2

Enter the coefficients of x3 : 3

Enter the constant: 6

EQUATION 3

Enter the coefficients of x1 : 2

Enter the coefficients of x2 : 3

Enter the coefficients of x3 : 1

Enter the constant: 6

Solutions are:

The value of 1 is 1.000
The value of 2 is 1.000
The value of 3 is 1.000
-----------------------------------------------
*/

No comments:

Post a Comment