追赶法解线性方程组出线的问题!
/*************************************************************************Program:marks(math3-7.c)
Programmer:zhuhao'feng
TESTED/COMPILED-Windows xp/Borland Turbo c 2.0
*************************************************************************/
#include<stdio.h>
#include<math.h>
void main()
{
float a[3][3] = {5,1,0,1,5,1,0,1,5}, b[3] = {17,14,7},x[3] = {0},y[3] = {0};
float temp;
int i,j,k;
for(i = 0;i < 3;i ++)
{
temp = 0;
for(j = 0,k = i + 1;j < i;j ++)
temp += a[j][i]*a[i][j];
a[i][i] = a[i][i] - temp;
a[i][k] = a[i][k]/a[i][i];
}
y[0] = b[0]/a[0][0];
for(i = 1;i < 3;i ++)
{
temp = 0;
for(j = 0;j < i;j ++)
temp += y[j]*a[i][j];
y[i] = (b[i] - temp)/a[i][i];
}
printf("the changed array is:\n");
for(i = 0;i < 3;i ++)
{
for(j = 0;j < 3;j ++)
printf("%10.5f",a[i][j]);
printf("|%10.5f\n",y[i]);
}
x[2] = y[2];
for(i = 1;i >= 0;i --)
{
temp = 0;
for(j = 2;j > i;j --)
temp += x[j]*a[i][j];
x[i] = y[i] - temp;
}
printf("the array answer is x[3]=[");
for(i = 0;i < 3;i ++)
printf("%10.5f",x[i]);
printf("]\n");
}
我调试的时候发现数组b[0]的值在红线处自动变化。
我在windows和Linux下都调试出线问题
请高手解答