#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int n,i,j,k;
float a[10][10],x[10],u;
//clrscr();
printf("enter the
number of equations :");
scanf("%d",&n);
printf("\nenter the
co-efficients of equations\n");
for(i=1;i<=n;i++)
for(j=1;j<=(n+1);j++)
scanf("%f",&a[i][j]);
printf("\nentered
co-efficient matrix is\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=(n+1);j++)
printf("%.2f\t",a[i][j]);
printf("\n");
}
//Diagonalisation Steps//
for(k=1;k<=n;k++)
for(i=1;i<=n;i++)
{
if(i != k)
{
u=a[i][k]/a[k][k];
for(j=1;j<=(n+1);j++)
a[i][j]=a[i][j]-(u*a[k][j]);
}
}
printf("\nDiagonalised matrix
is\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=(n+1);j++)
printf("%.2f\t",a[i][j]);
printf("\n");
}
//End Diagonalisation Steps//
//Forward Substitution Steps //
x[n]=a[n][n+1]/a[n][n];
for(i=1;i<=n;i++)
x[i]=(a[i][n+1])/a[i][i];
printf("\nsolution vector is\n");
for(i=1;i<=n;i++)
printf("x[%d]=%.2f\n",i,x[i]);
getch();
}
No comments:
Write comments