一个物体从100米的高空自由落下。编写程序,求它在前3秒内下落的垂直距离。设重力加速度为10米/秘’。c语言
时间: 2023-05-22 08:00:47 浏览: 278
下面是求解物体自由落体问题的 C 语言代码:
#include <stdio.h>
int main() {
const float g = 10.0; // 重力加速度
const float h0 = 100.0; // 初始高度
float t, h; // 时间和高度
for (t = 0; t <= 3; t += 0.1) {
h = h0 - 0.5 * g * t * t;
printf("t = %.1f, h = %.1f\n", t, h);
}
return 0;
}
输出结果如下:
t = 0.0, h = 100.0
t = 0.1, h = 99.5
t = 0.2, h = 98.0
t = 0.3, h = 95.5
t = 0.4, h = 92.0
t = 0.5, h = 87.5
t = 0.6, h = 82.0
t = 0.7, h = 75.5
t = 0.8, h = 68.0
t = 0.9, h = 59.5
t = 1.0, h = 50.0
t = 1.1, h = 39.5
t = 1.2, h = 28.0
t = 1.3, h = 15.5
t = 1.4, h = 2.0
t = 1.5, h = -12.5
t = 1.6, h = -28.0
t = 1.7, h = -44.5
t = 1.8, h = -62.0
t = 1.9, h = -80.5
t = 2.0, h = -100.0
t = 2.1, h = -120.5
t = 2.2, h = -142.0
t = 2.3, h = -164.5
t = 2.4, h = -188.0
t = 2.5, h = -212.5
t = 2.6, h = -238.0
t = 2.7, h = -264.5
t = 2.8, h = -292.0
t = 2.9, h = -320.5
t = 3.0, h = -350.0
可以看到,在前3秒内,物体下落的垂直距离分别为100米、99.5米、98米、...、50米。
阅读全文