发布网友 发布时间:2022-06-12 10:04
共3个回答
热心网友 时间:2023-10-09 00:35
是要两个程序吗?
第1个:
#include<stdio.h>
#include<math.h>
double gs(double x,double T)
{
double temp;
temp=15.5307-44.3977*x+80.9385*x*x+(-32597.5+122835*x+160757*x*x)/T;
return temp;
}
void main(void)
{
double P,x,lg_P,T;
printf("Please input x:");
scanf("%lf",&x);
A: printf("Please input T:");
scanf("%lf",&T);
if(T==0)//分母不能为0,为0重输
goto A;
lg_P=gs(x,T);
P=pow(10,lg_P);
printf("\nlg_P=%.10f\n",lg_P);
printf("P=%e\n",P);
}
第2个:
#include<stdio.h>
#include<math.h>
double g(double P)
{
double temp;
temp=121.761+5.89e-7*(P-21.4e+5)-1e-15*(P*P-4.584e+10);
return temp;
}
double q(double x)
{
double temp;
temp=-40.2-569.5*x+610.7*x*x;
return temp;
}
double y(double x,double t)
{
double temp;
temp=1.52*t+2.54*x*t+(0.99*x-0.358)*1e-2*t*t;
return temp;
}
void main(void)
{
double h,P,t,x;
printf("Please input P:");
scanf("%lf",&P);
printf("Please input t:");
scanf("%lf",&t);
printf("Please input x:");
scanf("%lf",&x);
h=g(P)+q(x)+y(x,t);
printf("h=%.20e\n",h);
}
补充第1题:
#include<stdio.h>/* ------- 已知x,P,求T ------- */
#include<math.h>
double gs(double P,double x)
{
double temp1,temp2;
temp1=log10(P);
temp1=temp1-15.5307+44.3977*x-80.9385*x*x;
temp2=-32597.5+122835*x+160757*x*x;
temp2=temp2/temp1;
return temp2;
}
void main(void)
{
double P,x,T;
printf("Please input x:");
scanf("%lf",&x);
A: printf("Please input P:");
scanf("%lf",&P);
if(P<=0)//对数底数不能小于等于0,小于等于0重输
{
printf("'P' must be above 0 ,input again.\n");
goto A;
}
T=gs(P,x);
printf("T=%.20e\n",T);
}
#include<stdio.h>/* ------- 已知P,T,求x ------- */
#include<math.h>
void gs(double P,double T)
{
double a,b,c,delta,x1,x2,tmp;
a=80.9385-160757/T;
b=122835/T-44.3977;
c=15.5307-32597.5/T-log10(P);
delta=b*b-4*a*c;
printf("Result:\n");
if(delta>0)
{
tmp=sqrt(delta);
x1=(-b+tmp)/(2*a);
x2=(-b-tmp)/(2*a);
printf("delta>0,there are two answers:x1=%.20e , x2=%.20e\n",x1,x2);
}
else if(delta==0)
{
x1=(-b)/(2*a);
printf("delta=0,there is one answer:x1=x2=%.\n",x1);
}
else
{
printf("delta,<0,there is no answer.\n");
}
}
void main(void)
{
double P,T;
A: printf("Please input P:");
scanf("%lf",&P);
if(P<=0)//对数底数不能小于等于0,小于等于0重输
{
printf("'P' must be above 0 ,input again.\n");
goto A;
}
B: printf("Please input T:");
scanf("%lf",&T);
if(T==0)//分母不能为0,为0重输
{
printf("'T' can not be 0 ,input again.\n");
goto B;
}
gs(P,T);
}
热心网友 时间:2023-10-09 00:35
请问你的 lgP 是2为底还是10为底?我以10为底来计算。
#include <stdio.h>
#include <math.h>
/* the first one */
double Pf(double T, double x){
double t = 15.5307 - 44.3977*x + 80.9385*x*x + 1.0 / (-32597.5 + 122835 * x - 160757 * x * x);
return pow(10, t);
}
/* the second one*/
double g(double P){
return 121.761 + 5.89*(1E-7)*(P - 21.4*(1E5)) - (1E-15)*(P*P - 4.584*(1E10));
}
double q(double x){
return -40.2 - 569.5*x + 610.7*x*x;
}
double y(double x, double t){
return 1.52*t + 2.54*x*t + (0.99*x - 0.358)*(1E-2)*t*t;
}
double h(double P, double t, double x){
return x*g(P) + q(x) + y(x, t);
}
int main(){
double T, x, ans1;
double P, t, ans2;
scanf("%lf%lf", &T, &x);
printf("T=%lf x=%lf\n", T, x);
ans1 = Pf(T, x);
printf("Result = %lf\n", ans1);
scanf("%lf%lf%lf", &P, &t, &x);
printf("P=%lf t=%lf x=%lf\n", P, t, x);
ans2 = h(P, t, x);
printf("Result = %lf\n", ans2);
return 0;
}
追问第一个应该出错了,跟手动输入的结果不一样
追答
C语言可修改为。
热心网友 时间:2023-10-09 00:35
这你只要设几个变量,吧公式输进去就可以了