
c++球体落下弹起运动的源程序 20
c语言实习要用5、模拟弹球的动画题目详解:小球从空中落下,弹起,再落下,弹起幅度越来越小,直至停下。...
c语言实习要用
5、模拟弹球的动画题目详解:
小球从空中落下,弹起,再落下,弹起幅度越来越小,直至停下。 展开
5、模拟弹球的动画题目详解:
小球从空中落下,弹起,再落下,弹起幅度越来越小,直至停下。 展开
2个回答
展开全部
#include <iostream>
using namespace std;
int main()
{
double m,n,d,t;
cin>>m>>n;
d=m;
for(int i=1;i<=n-1;i++)
{
m=m*0.5;
d+=2*m;
}
m=m*0.5;
cout.setf(ios::fixed); cout.precision(2);
cout<<m<<" "<<d<<endl;
return 0;
}
试试吧不知合不合要求
Sample Input
1000 5
Sample Output
31.25 2875.00
结果
它在第N次落地时反弹多高?共经过多少米?
展开全部
// 环境,easyx + vc
#include <graphics.h>
#include <conio.h>
#include <math.h>
#include <stdio.h>
#define WIDTH 100
#define HEIGHT 400
#define RADIUS 10
#define TIMEDIV 0.001
void f(double air_k, int time_slow)
{
int y_pos = HEIGHT - RADIUS * 2;
bool is_down = true;
double v = 0;
BeginBatchDraw();
for (;;)
{
Sleep((unsigned long)(TIMEDIV * 1000 * time_slow));
double a = ((is_down ? 1 : -1) - air_k) * 9.8;
y_pos -= (is_down ? 1 : -1) * (int)ceil(v * TIMEDIV + 0.5 * a * TIMEDIV * TIMEDIV);
if (y_pos <= 0)
{
y_pos = 0;
if (is_down) is_down = false;
else break;
}
v += a * TIMEDIV;
if (!is_down && v <= 0) is_down = true;
cleardevice();
solidcircle(WIDTH / 2, y_pos, RADIUS);
FlushBatchDraw();
if (kbhit() && getch() == ' ') break;
}EndBatchDraw();
}
int main()
{
initgraph(WIDTH, HEIGHT, SHOWCONSOLE);
setaspectratio(1, -1);
setorigin(0, HEIGHT - RADIUS);
do {
double air_k;
int time_slow;
system("cls");
printf("ÇëÊäÈë¿ÕÆø×èÁ¦ÏµÊý£¨Ð¡Êý£¬0 ~ 1£©");
scanf("%lf", &air_k);
printf("ºÍÂý·Å±¶Êý£¨ÕûÊý£¬´óÓÚµÈÓÚ1£©: ");
scanf("%d", &time_slow);
printf("°´¿Õ¸ñ¿ÉÖØпªÊ¼");
f(air_k, time_slow);
Sleep(1);
} while (1);
getch();
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询