#include <stdio.h>
#include <stdlib.h>
int main()
{
int s;//定义s累计距离
float n,p;//定义n米下落,定义p反弹高度
scanf("%f",&n);//键盘输入n
s=n;//将n赋值给s
p=n;//将n赋值给p
for(int i=2;i<=10;i++)//循环,从第二次落地开始;球经过10次落地
{
p=p/2;//落地后反弹到原来高度的一半
s=s+2*p;//落地累加经过米数
}
printf("%d",s);//输出s
}
输出结果
Input:
5
5 times:
287.500
3.125
Process returned 0 (0x0) execution time : 7.117 s
Press any key to continue.