c语言自练,OJ系统第九题。
题目描述
一个物体从100米的高空自由落下。编写程序,求它在前3秒内下落的垂直距离。设重力加速度为10米/秒2。
输入
本题目没有输入。
输出
按照下列格式输出
height = 垂直距离值
结果保留2位小数。
本题中出现小数概念,定义小数可以使用float与double两种方式
对应两种不同的输出小数形式
float:%f,如果限制小数点后n位,使用%.nf的方式输出
double:%lf,如果限制小数点后n位,使用%.nlf的方式输出
实例如下:
#include<stdio.h>
int main()
{
int g = 10, t = 3;
float height;
height = 0.5 * g * t * t;
printf("height = %.2f", height);
return 0;
}
#include<stdio.h>
int main()
{
int g = 10, t = 3;
double height;
height = 0.5 * g * t * t;
printf("height = %.2lf", height);
return 0;
}