有偿哦!!
#include<stdio.h>
double a[15],h,sum;//a[i]表示第i次撞地弹起高度
int main()
{
int n;
scanf("%lf %d",&h,&n);
for(int i=1;i<=n;i++)
{
if(i==1)
a[i]=h*1.0/2;
else
a[i]=a[i-1]*1.0/2;
}
for(int i=0;i<n;i++)//第n此撞地不会反弹,只求撞地之前
{
if(i==0)
sum+=h;//最开始只有下去
else
sum+=2*a[i];//每次都要有下去上来两个过程
}
printf("%.2f %.2f",sum,a[n]);
}
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632
这是一个简单的例子,和题目的要求需要再完善,供参考:
//效果:跳动的小球,触碰到边界后,发出声音,并弹回。
#include <stdio.h>
#include <windows.h>
#include <stdlib.h>
//小球速度
int velocity_x = 1 ,velocity_y = 1;
//小球初始位置
int x=3,y=1;
//显示
int left = 0,right = 20,top = 0,bottom =10;
void show_board(void)
{
for(int i=top;i<=bottom+1;i++)
{
for(int j=left;j<=right+1;j++)
{
if(x==i&&y==j)
printf("o");
else
{
if(i==0 || i==bottom+1)
{
printf("-");
}
else if(j==0 || j==right+1)
{
printf("|");
}
else
{
printf(" ");
}
}
}
printf("\n");
}
}
int main(int argc,const char* argv[])
{
while(1)
{
x += velocity_x;
y += velocity_y;
//显示刷新并显示
system("cls");
show_board();
//show_ball();
//休眠50ms
Sleep(100);
//到达边界 修改速度方向 并响铃
if((x == top+1)||(x == bottom))
{
printf("\a");
velocity_x = -velocity_x;
}
if((y == left+1)||(y == right))
{
printf("\a");
velocity_y = -velocity_y;
}
}
return 0;
}