没测试,仅供参考
#include <stdio.h>
#include <math.h>
float m(float h) //求得m的值
{
float a,b;
a = 18.0;
b = 270.0;
return acos( (b*b - a*a + h*h) / (2*h*b));
}
float n(float h) //求得n的值
{
float a,b;
a = 18.0;
b = 270.0;
return acos((a*a - b*b + h*h)/ (2*h*a) );
}
float p(float h) //求得p值
{
return pow(tan(m(h))/tan(n(h)),2);
}
float calc(int floor,int up) //从下限到上限寻找最大值
{
float i,max,maxh;
i = floor;
max = p(i);
maxh = floor;
for(i = floor+0.1;i<up;i+=0.1){
if(p(i)>max){
max = p(i);
maxh = i;
}
}
printf("%f\n%f",max,maxh);
}
int main()
{
int up,floor;
scanf("%f %f",&floor,&up);
//舍弃不符合要求的范围
if(floor<270.0){
floor = 270.0;
}
if(up>306.0){
up = 306;
}
calc(floor,up);
return 0;
}
|