Friday, April 10, 2015

Gauss Jordan Elimination Method in C

#include<stdio.h>
#include<conio.h>
 void main()
{
int n,i,j,k;

float a[10][10],x,r;
clrscr();
printf("\n Enter the no.of unknowns= ");
scanf("%d",&n);
printf("Enter the elements of the augmented matrix [a/b]");
for(i=1;i<=n;i++)
{
for(j=1;j<=n+1;j++)
{
printf("\n Enter the element [%d][%d]=",i,j);
scanf("%f"&a[i][j]);
}}
printf("\n Enter the augmented matrix");
for(i=1;i<=n,i++)
{
printf("\n");
for(j=1;j<=n+1;j++)
{
printf("% 2f \t”, a[i][j]);
}}
// row operation
for (i=1;i<=n;i++)
{
for(j=1;j<=n+1;j++)
{
if(j!=i)
r=a[j][i]/a[i][j];
for(k=1;k<=n+1;k++)
a[j][k]-=r*a[i][k];
}}}
printf("\n the row operated matrix is;");
for(i=1;i<=n,i++)
{
printf("\n");
for(j=1;j<=n+1;j++)
{
printf("% 2f\t",a[i][j]);
}}
// the solution calculation begins from here
for(i=1;i<=n;i++)
{
x=a[i][n+1]/a[i][j];
printf("/n the value of x %d=% 2f”,i,x);
}
getch();
}

No comments:

Post a Comment