当前位置: 代码迷 >> C语言 >> [求助]数组赋值问题
  详细解决方案

[求助]数组赋值问题

热度:329   发布时间:2006-08-27 20:07:18.0
[求助]数组赋值问题

定义一个数组,能不能用循环语句一个个计算赋值,再输出呀,我编的没错误,可不能正常运行呀。
请问一下高手怎么回事呀???
#include<stdio.h>
#include<math.h>
float lre(float u,float d)
{
float re,v, float tf[3][10000];
int i,j;
v=(8.123*(tf[i][j]-273.15)*(tf[i][j]-273.15)*1e-5+9.1945*0.01*(tf[i][j]-273.15)+13.198)*1e-6;
re=u*d/v;
return (re);
}
float hr(float d,float k,float u)
{
float r=0.0276/d;
float h1,h,h2,x,a,float tf[3][10000];
x=lre(u,d);
a=d/k;
if(x>2300)
{
h1=0.226421*r*pow(a,0.318257)*pow(x,0.631779);
h2=0.357498*r*pow(a,0.311957)*pow(x,0.600192);
h=(h1+h2)/2;
return(h);
}
else
h1=0.866633*r*pow(a,0.46642)*pow(x,0.453158);
h2=1.494713*r*pow(a,0.85346)*pow(x,0.405349);
h=(h1+h2)/2;
return(h);
}
#define USER_INPUT 0 //如果它为1的话,就用键盘输入,如果为0的话,就直接用默认值。

void main()
{
int i,j;
float u,ts,n,l,p,r,c;
float t[3][10000],tf[3][10000];
float d,h,k,e,y,s,a,v,qv,qv1;
float p1=1.17,cp1=1.005,p2=8070,cp2=436;

#if (USER_INPUT)
printf("input u,d,k,ts,n,l,e,ui,iu:\n");
scanf("%f,%f,%f,%f,%f,%f,%f,%f",&u,&d,&k,&ts,&n,&l,&);
#else
u=6,d=0.009,k=0.08,ts=50,n=20,l=3,e=0.001,p=60;
#endif

s=8*n*(l*k+l*e);
a=4*n*d*k;
v=4*n*l*k*e;
qv=p*ts;
tf[0][0]=313;
t[0][0]=313;
for(j=0;j<ts;j++)
{
c=p2*cp2*v;
for(i=0;i<3;i++)
h=hr(u,d,k);
r=h*a;
qv1=qv*v/4+p1*cp1*(tf[i][j]-t[i][j-1]+qv*v/(4*h*s))*exp(-ts/r/c);
tf[i][j]=(u*t[i-1][j]+qv1/l/d/cp1+u*t[i][j-1])/(u+p1*l);
t[i][j]=tf[i][j]+qv*v/(4*h*s)-(tf-t+qv*v/(4*h*s))*exp(-1/r/c);
}
printf("tf=%f",tf[i][j]);
printf(" t=%f",t[i][j]);
}

搜索更多相关的解决方案: 赋值  float  include  lre  定义  

----------------解决方案--------------------------------------------------------

#include<stdio.h>
#include<math.h>
float lre(float u,float d)
{
float re,v;
float tf[3][10000];
int i,j;
v=(8.123*(tf[i][j]-273.15)*(tf[i][j]-273.15)*1e-5+9.1945*0.01*(tf[i][j]-273.15)+13.198)*1e-6;
re=u*d/v;
return (re);
}
float hr(float d,float k,float u)
{
float r=0.0276/d;
float h1,h,h2,x,a;
float tf[3][10000];
x=lre(u,d);
a=d/k;
if(x>2300)
{
h1=0.226421*r*pow(a,0.318257)*pow(x,0.631779);
h2=0.357498*r*pow(a,0.311957)*pow(x,0.600192);
h=(h1+h2)/2;
return(h);
}
else
h1=0.866633*r*pow(a,0.46642)*pow(x,0.453158);
h2=1.494713*r*pow(a,0.85346)*pow(x,0.405349);
h=(h1+h2)/2;
return(h);
}
#define USER_INPUT 0 //如果它为1的话,就用键盘输入,如果为0的话,就直接用默认值。

int main()
{
int i,j;
float u,ts,n,l,p,r,c;
float t[3][10000],tf[3][10000];
float d,h,k,e,y,s,a,v,qv,qv1;
float p1=1.17,cp1=1.005,p2=8070,cp2=436;

#if (USER_INPUT)
printf("input u,d,k,ts,n,l,e,ui,iu:\n");
scanf("%f,%f,%f,%f,%f,%f,%f,%f",&u,&d,&k,&ts,&n,&l,&);
#else
u=6,d=0.009,k=0.08,ts=50,n=20,l=3,e=0.001,p=60;
#endif

s=8*n*(l*k+l*e);
a=4*n*d*k;
v=4*n*l*k*e;
qv=p*ts;
tf[0][0]=313;
t[0][0]=313;
for(j=0;j<ts;j++)
{
c=p2*cp2*v;
for(i=0;i<3;i++)
h=hr(u,d,k);
r=h*a;
qv1=qv*v/4+p1*cp1*(tf[i][j]-t[i][j-1]+qv*v/(4*h*s))*exp(-ts/r/c);
tf[i][j]=(u*t[i-1][j]+qv1/l/d/cp1+u*t[i][j-1])/(u+p1*l);
t[i][j]=tf[i][j]+qv*v/(4*h*s)-(tf-t+qv*v/(4*h*s))*exp(-1/r/c);
}
printf("tf=%f",tf[i][j]);
printf(" t=%f",t[i][j]);


----------------解决方案--------------------------------------------------------
float h1,h,h2,x,a,float tf[3][10000];
float re,v, float tf[3][10000];
这两个都过不得
----------------解决方案--------------------------------------------------------
是呀,要怎么改才行呀???
----------------解决方案--------------------------------------------------------

高手帮帮忙呀,我试了一下用指针,可不太会,还是不行呀??


----------------解决方案--------------------------------------------------------
以下是引用何苦学C在2006-8-27 20:22:19的发言:
float h1,h,h2,x,a,float tf[3][10000];
float re,v, float tf[3][10000];
这两个都过不得

前面定义了类型后面就不用再写了,改为;
float h1,h,h2,x,a, tf[3][10000];
float re,v, tf[3][10000];

----------------解决方案--------------------------------------------------------
你的tf占用了120k左右,大于64K
数组太大了,
要改用其他模式
----------------解决方案--------------------------------------------------------
i,j应该不用定义两次吧!
----------------解决方案--------------------------------------------------------

程序修改中,用了指针,可数据还是传不过去怎么办呀,老传一个。
#include<iostream.h>
#include<stdio.h>
#include<math.h>
float lre(float u,float d,float *tf, int i,int j)
{
float re,v;

v=(8.123*(*tf-273.15)*(*tf-273.15)*1e-5+9.1945*0.01*(*tf-273.15)+13.198)*1e-6;
re=u*d/v;
return (re);
}
float hr(float u,float d,float k,int i,int j,float *tf)

{ float r=0.0276/d;
float h1,h,h2,x,a;
x=lre(u,d,tf,i,j);
a=d/k;
if(x>2300)
{
h1=0.226421*r*pow(a,0.318257)*pow(x,0.631779);
h2=0.357498*r*pow(a,0.311957)*pow(x,0.600192);
h=(h1+h2)/2;
return(h);
}
else
h1=0.866633*r*pow(a,0.46642)*pow(x,0.453158);
h2=1.494713*r*pow(a,0.85346)*pow(x,0.405349);
h=(h1+h2)/2;
return(h);
}
#define USER_INPUT 0 //如果它为1的话,就用键盘输入,如果为0的话,就直接用默认值。

void main()
{
int i,j;
float u,ts,n,l,p,r,c;
float t[4][100],tf[4][100];
float d,h,k,e,y,s,a,v,qv,qv1;
float p1=1.17,cp1=1.005,p2=8070,cp2=436;


#if (USER_INPUT)
printf("input u,d,k,ts,n,l,e,ui,iu:\n");
scanf("%f,%f,%f,%f,%f,%f,%f,%f",&u,&d,&k,&ts,&n,&l,&);
#else
u=6,d=0.009,k=0.08,ts=50,n=20,l=3,e=0.001,p=60;
#endif

s=8*n*(l*k+l*e);
a=4*n*d*k;
v=4*n*l*k*e;
qv=p*ts;
tf[0][0]=313;
t[0][0]=313;

for(j=0;j<=ts;j++)
{
c=p2*cp2*v;
for(i=0;i<=3;i++)
h=hr(u,d,k,i,j,*tf);
r=h*a;
t[i][j]=tf[i][j]+qv*v/(4*h*s)-(tf[i][j]-t[i][j-1]+qv*v/(4*h*s))*exp(-1/r/c);
qv1=qv*v/4+p1*cp1*(tf[i][j]-t[i][j-1]+qv*v/(4*h*s))*exp(-ts/r/c);
tf[i][j]=(u*t[i-1][j]+qv1/l/d/cp1+u*t[i][j-1])/(u+p1*l);
printf("tf=%f",tf[i][j]);
printf(" t=%f\n",t[i][j]);
}
}


----------------解决方案--------------------------------------------------------
要使初始值,tf[i][j]-t[i][j-1]=0怎么办呀???
因为tf[0][0]=313,而t[0][0]=313,t[0][0-1]怎么办,它默认的为0.
----------------解决方案--------------------------------------------------------
  相关解决方案