请求帮助解答!谢谢!!!
请求帮助解答!谢谢!!!
#include <math.h>
#include <stdio.h>
int main(void)
{
double x = 2.0, y = 3.0;
printf("%lf raised to %lf is %lf\n", x, y, pow(x, y));
return 0;
}
错误几乎都出在求x的y次幂
/*程序名为f1.cpp*/
/*理想气体状态下的比内能u0*/
double u0(double tr,double tc,double d[])
{
double max,max1,max2;
int i;
max1=0;
for(i=0;i<=4;i++)
{
max2=d[i]*double pow(double tr,double (i+1))/(i+1);
max1=max1+max2;
}
max=tc*max1;
return(max);
}
/*理想气体状态下的定容比熵s0*/
double s0(double tr,double d[])
{
double max,max1,max2;
int i;
max1=0;
for(i=0;i<=4;i++)
{
max2=d[i]*double pow(double tr,double i)/i;
max1=max1+max2;
}
max=d[0]*double log(double tr)+max1;
return(max);
}
/*中间变量l*/
double l(int q,double tr,int n,double den,double b[][4])
{
int i,j;
double l1,l2,r;
l1=0;
l2=0;
for(i=1;i<=n;i++)
{
for(j=1;j<=3;j++)
{
{
if(q=1)
r=1;
else if(q=2)
r=double(1/i);
else
r=double(j/i);
}
l1=l1+r*b[i][j]*double pow(double den,double i)*double pow(double tr,double i);
}
l2=l2+l1;
}
return(l2);
}
/*气相区的状态方程*/
double z(double b[][4],double den,double tr,int n)
{
int i,j;
double z1,z2,z3;
z1=0;
z2=0;
for(i=1;i<=n;i++)
{
for(j=0;j<=3;j++)
{
z1=z1+b[i][j]/double pow(double tr,double j);
}
z2=z2+z1*double pow(double den,double i);
}
z3=1+z2;
return(z3);
}
/*主程序*/
#include"stdio.h"
#include"math.h"
void main()
{
int n,i,j;
scanf("%d",&n);
double tr,tc,p,hc,sc,d[5],b[n][4],R,h,s,den,den1,z0;
/*输入已知数据*/
printf("输入对比温度:\n");
scanf("%d",&tr);
printf("输入临界温度:\n");
scanf("%d",&tc);
printf("输入压强:\n");
scanf("%d",&p);
printf("输入常数hc和sc:\n");
scanf("%d.%d",&hc,&sc);
printf("输入物质常数:\n");
for(i=0;i<=4;i++)
scanf("%d",d[i]);
printf("输入b值:\n");
for(i=1;i<=n;i++)
{
for(j=0;j<=3;j++)
{scanf("%d",&b[i][j]);}
printf("\n");
}
R=8.3145;
/*利用迭代法求出密度*/
den1=p/(10*R*tc*tr);
do
{
den=den1;
z0=z(b,den,tr,9);
den1=p/(10*R*tc*tr*z0);
}while(fabs((den1-den)/den)>1e-5);
/*求出焓值h和熵值s*/
h=R*tc*tr*(1+l(1,tr,n,den,b)+l(3,tr,n,den,b))+u0(tr,tc,d)+hc;
s=R*(l(3,tr,n,den,b)-l(2,tr,n,den,b)-double log(double den))+s0(tr,d)+sc;
/*输出状态各个参数*/
printf("输出各个参数:\n");
printf("压强:%d\n",p);
printf("密度:%d\n",den);
printf("焓值:%d\n",h);
printf("熵值:%d\n",s);
}
程序我没看 5楼的可以做如下修改
max2=d[i]*pow(tr,i+1)/(i+1);
或者(这样其实没什么必要)
max2=d[i]*pow( (double) tr,(double) (i+1) )/(i+1);