C语言实验——拍皮球
Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
小瑜3岁了,很喜欢玩皮球,看来今后喜欢打篮球的_。最近她发现球从手中落下时,每次落地后反跳回原高度的一半,再落下,每次球落地时数球跳了几次,数到n次时爸爸在边上喊停,问小瑜现在球到底总共走了多少距离,小瑜故作沉思状,爸爸又问接下来小球能跳多高啊,小瑜摇摇头,心想还没跳我怎么知道啊,难道爸爸是神啊!这时的你在边上出主意想给小瑜写个程序计算一下,因此任务就交给你啦!假设球的初始高度为h,计算第n次落地时球经过的距离,以及落地后反弹能有多高。
Input
输入数据有多组,第一行为数据的组数t,下面t行为t组数据,每行有两个数h和n,分别用空格分隔。
Output
输出第n次反弹时球经过的距离和球最后的高度,保留小数点后2位。
Sample Input
2
100 1
100.0 2
Sample Output
100.00 50.00
200.00 25.00
Hint
Source
正确?
#include<stdio.h>
#include<math.h>
void f(double h,int n)
{
double s,i;
for(i=0; i<n; i++)
{
if(i==0)s=s+h;
else s=s+h2;
h=h1.0/2;
}
printf("%.2lf %.2lf\n",s,h);
}
int main()
{
int t;
scanf("%d",&t);
while(t–)
{
double h;
int n;
scanf("%lf %d",&h,&n);
f(h,n);
}
return 0;
}
错误?
#include<stdio.h>
#include<math.h>
void f(double h,int n)
{
double s;
int i;
for(i=0; i<n; i++)
{
if(i==0)s=s+h;
else s=s+h2;
h=h1.0/2;
}
printf("%.2lf %.2lf\n",s,h);
}
int main()
{
int t;
scanf("%d",&t);
while(t–)
{
double h;
int n;
scanf("%lf %d",&h,&n);
f(h,n);
}
return 0;
}
为什么i必须是double,int 就错了