想问一下各位大神,这个代码为什么运行时我要输入第二个数组时会突然中止?
#include<iostream>using namespace std;
#include<cmath>
double jud(double Y[],int n,double T[],int j,float c,float d);
void main()
{
int z;
float x;
double m,l;
float c,d;
double *T=new double[z];
double *Y=new double[z];
cout<<"请输入每列数据的个数"<<endl;
cin>>z;
cout<<"请输入精确度"<<endl;
cin>>x;
cout<<"请输入参数的取值范围"<<endl;
cin>>c;
cin>>d;
cout<<"请依次输入第一列数据的数值:";
for(int i=0;i<z;i++)
{
cin>>m;
T[i]=m;
}
cout<<"请依次输入第二列数据的数值:";
for(int j=0;j<z;j++)
{
cin>>l;
Y[j]=l;
}
float kd1=c+0.618*(d-c);
float kd2=d-0.618*(d-c);
while(fabs(kd1-kd2)>x)
{
if(jud(Y,z,T,z,kd1,kd2)<0)
{
c=kd2;
kd2=kd1;
d=d;
}
else if(jud(Y,z,T,z,kd1,kd2)>0)
{
d=kd1;
kd1=kd2;
c=c;
}
else if(jud(Y,z,T,z,kd1,kd2)==0)
{
c=kd2;
d=kd1;
}
}
cout<<"所求值为"<<(c+d)*0.5;
}
double jud(double Y[],int n,double T[],int j,float c,float d)
{
float kd1=c+0.618*(d-c);
float kd2=d-0.618*(d-c);
float sum1=0;
float sum2=0;
for(int i=0;i<=n;i++)
{
sum1=pow(Y[i]-0.202*exp(-kd1*T[i]),2)+sum1;
}
for(int k=0;k<=j;k++)
{
sum2=pow(Y[k]-0.202*exp(-kd2*T[k]),2)+sum2;
}
return sum1-sum2;
}