帮忙看道C语言题,在线等

来源:百度知道 编辑:UC知道 时间:2024/06/06 14:04:34
一个球从100米高度自由落下,每次落地后反跳回原高度的一半,再落下。求它在第10次落地时,共经过多少米?第10次反跳多高?
用C语言编写啊!

#include<stdio.h>

void main()
{
float S=100.0,sum=100.0;
int i,j=0;
printf("please input :\n");//输入落地次数
scanf("%d",&i);
while(j<i)
{
S=S/2;
sum+=2*S;
j++;
}
printf("%f\n%f",sum,S);//sum共经过的米,S反跳高度
}

main()
{
float sn=100.0,hn=sn/2;
int n;
for(n=2;n<=10;n++)
{
sn=sn+2*hn;/*第n次落地时共经过的米数*/
hn=hn/2; /*第n次反跳高度*/
}
printf("the total of road is %f\n",sn);
printf("the tenth is %f meter\n",hn);
}