Проблема в том, что на выходе должны отображаться значения x
, y
и z
с первой и до последней итерации, где big
меньше или равно e
. Но проблема в том, что он показывает только последнюю итерацию. Как вывести другие итерации? Вот мой код:
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
void main()
{
float a[50][50],x[50],e=0.0010,big,temp,relerror,sum;
int n=3,i,j,maxit=50,itr;
char ch;
clrscr();
for(i=1;i<=n;i++)
{
clrscr();
printf("\n\t\t\t ----EQUATION %d-----",i);
printf("\n\tEnter your desired numerical coefficients for x, y and z\n\t\t\tthen the constant's value.\n\t (Press enter each time you are done on your input.)\n");
for(j=1;j<=n+1;j++)
scanf("%f",&a[i][j]);
}
clrscr();
for(i=1;i<=n;i++)
x[i]=0;
for(itr=1;itr<=maxit;itr++)
{
big=0;
for(i=1;i<=n;i++)
{
sum=0;
for(j=1;j<=n;j++)
{
if(i!=j)
sum=sum+a[i][j]*x[j];
}
temp=(a[i][n+1]-sum)/a[i][i];
relerror=fabs((x[i]-temp)/temp);
if(relerror>big)
big=relerror;
x[i]=temp;
}
if(big<=e)
{
printf("\t k\t x\t y\t z\t xe\t ye\t et\n");
printf("\t %d",itr);
for(i=1;i<=n;i++)
printf("\t %.4f",x[i]);
printf(" %.4f",sum);
printf(" %.4f",big);
while(itr>1)
{
itr=--itr;
printf("\n\t %d",itr);}
getch();
exit(1);
}
}
printf("Does not converge in %d iteration \n",maxit);
getch();
}
}