由物理公式可知
根据公式我们可以得到物体落地的时间为sqrt(20)。如果前3秒内它已落地,则自由落体的垂直距离为100。不然,则运用公式计算。
/*计算物体自由下落的距离:一个物体从100米的高空自由落下,求它在前3秒内下落的垂直距离*/
#include<stdio.h>
#include<math.h>
int main(){
int time=3,h=100,g=10;
int s;
if(time<sqrt(20)){
s=g*time*time/2;
printf("%d",s);
}else{
s=100;
printf("%d",s);
}
return 0;
}
运行结果如下: