【问题标题】:Why is 22 the only result for the eheight?为什么 22 是身高的唯一结果?
【发布时间】:2022-11-18 11:08:34
【问题描述】:

我使用函数 f 以时间作为输入来评估 eheight。

#include <iostream>
#include <cmath>
using namespace std;

float f(float x)
{
    return(22 - ((1 / 2) * 386.4 * pow(x, 2)));
}
int main()
{
    float time[9] = { 0.03,0.0633,0.0967,0.13,0.1633,0.1967,0.2300,0.2633,0.2967 };
    float height[9] = { 22,21.5,20.5,18.8,17,14.5,12.0,8,3 };
    float eheight[9];
    cout << "Time(s)\tHeight(in)\tExperimental height(s)"<<endl;
    for (int i = 0; i <= 8; ++i)
    {
        eheight[i] = f(time[i]);
        cout << time[i]<<"\t"<<height[i]<<"\t\t"<<eheight[i]<< endl;
    }
    
}

我使用函数 f 以时间作为输入来评估 eheight。

【问题讨论】:

    标签: arrays function visual-c++


    【解决方案1】:
        #include <iostream>
    #include <cmath>
    using namespace std;
    
    float f(float x)
    {
        return(22 - 0.5 * 386.4 * pow(x, 2));
    }
    int main()
    {
        float time[9] = { 0.03,0.0633,0.0967,0.13,0.1633,0.1967,0.2300,0.2633,0.2967 };
        float height[9] = { 22,21.5,20.5,18.8,17,14.5,12.0,8,3 };
        float eheight[9];
        cout << "Time(s)	Height(in)	Experimental height(s)"<<endl;
        for (int i = 0; i <= 8; ++i)
        {
            eheight[i] = f(time[i]);
            cout << time[i]<<"	"<<height[i]<<"		"<<eheight[i]<< endl;
        }
        
    }
    

    【讨论】:

      猜你喜欢
      • 2017-11-02
      • 1970-01-01
      • 2012-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多