#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
float x[10],y[10],a[10][10];
int i,j,k,n,itr;
printf("\n ENTER THE SIZE OF MATRIX n:");
scanf("%d",&n);
printf("\n ENTER MATRIX ELEMENTS AND RHS:\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n+1;j++)
scanf("%f",&a[i][j]);
}
for(i=1;i<=n;i++)
{
x[i]=0.0;
y[j]=0.0;
}
itr=0.0;
top:
itr=itr+1;
for(i=1;i<=n;i++)
{
x[i]=a[i][n+1];
for(j=1;j<=n;j++)
{
if(i==j)
continue;
else
x[i]=x[i]-a[i][j]*x[j];
}
x[i]=x[i]/a[i][j];
}
for(k=1;k<=n;k++)
if(fabs(x[k]-y[k])>0.0001)
{
printf("\n ITERATION=%d}",itr);
for(i=1;i<=n;i++)
{
y[i]=x[i];
printf("\n x(%d)=%f",i,x[i]);
}
goto top;
}
else
continue;
return;
}
No comments:
Post a Comment