当前位置:首页 » 编程语言 » C语言下落的小球
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

C语言下落的小球

发布时间: 2022-10-24 17:56:33

c语言程序设计小球的自由落体运动

#include <graphics.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int main(void)
{int gmode,gdriver=DETECT;
void *ball;
int x,y,t,f,v;
unsigned int size;
initgraph(&gdriver,&gmode, " ");
x=100;
y=200;
t=0;
f=0.1;
circle(x+10,y,10);
size=imagesize(x,y-10,x+20,y+10);
ball=malloc(size);
setfillstyle(SOLID_FILL,BLACK);
while(!kbhit()){
cleardevice();
t++;
y=y-9.8*(1-f)*t*t/2;
outtextxy(100,100, "v ");
v=(1-f)*9.8*t;
circle(x+10,y,10);
printf( "%d ",v);
delay(1000);
}
free(ball);
closegraph();
return 0;

Ⅱ 利用C语言来写动画该怎么写例如写一个小球做自由落体运动

load一张小球的图cximage类型 每次计算下落高度移动cximage 变量,c语言只能靠贴图,别的语言很简单

Ⅲ C语言编写程序解决小球下落反弹问题用

#include <stdio.h>
main()
{
float sum=0;
int i=0;
float height=100;
sum+=height;
while(i<10)
{
height=height/2;
sum+=2*height;
i++;
}
printf("总长度:%f 第10次跳%f米",sum,height);
}

Ⅳ 用c语言编程:一球从某一高度落下(整数,单位米),每次落地后反跳回原来高度的一半,再落下。

看你代码我理解m是初始高度 n是下落次数 s是总下落高度

不明白s=20初值做什么用,还有为什么要把double s=20,f=0,k=m; 定义变量写在大循环里,定义放在最上面,循环里只要赋值就好。否则你每次大循环都重复定义变量了。

下面是我根据你的写法,改的代码

#include<stdio.h>
#include<math.h>
intmain(void)
{
intn,k;//n指定的下落的次数k计数用
doublem,s;//m下落初始高度s下落的总高度
while(printf("请输入初始下落高度(整数)及要计算的下落次数:")&&scanf("%lf%d",&m,&n)!=EOF)
{
k=0;s=0;
while(n!=k)
{
s=s+m;
k++;
m=m/2;
}
printf("从%.0f米高度落下,在第%d次落地时,共经过%.8lf米?第%d次反弹高度%.8lf米 ",m*pow(2,n),n,s,n,m);
}
return0;
}

Ⅳ C语言 随机坠落的小球!!

提供给你我的小球运动程序,你可以按照着修改一下就可以了,可以取个随即数作为小球初始定位。其他自己慢慢琢磨
#include<graphics.h>
#include<stdio.h>
void main()
{
int gdriver=DETECT,gmode,x=320,y=240,k=1,l=1,size,*buf;
initgraph(&gdriver,&gmode,"bgi");
cleardevice();

setbkcolor(6);

while (!(kbhit()))
{
delay(5);

setcolor (4);
circle (x,y,5);
setfillstyle(1,4);
floodfill(x,y,4);

size=imagesize(x-5,y-5,x+5,y+5);
buf=(int *) malloc(size);
if(!buf)
{
printf("NOT enough memory!\n");
exit(0);
}
getimage(x-5,y-5,x+5,y+5,buf);
putimage(x-5,y-5,buf,1);
x+=k,y+=l;
putimage(x-5,y-5,buf,1);
free(buf);
if (y-5==0)
l=1;
else if (x==635)
k=-1;
else if (y==475)
l=-1;
else if (x-5==0)
k=1;
}
getch();
closegraph();

}

Ⅵ C语言做一个气球下落程序

你好!用c语言编写了这样的程序,你看行不?下面的代码……
#include<stdio.h>
#include <windows.h>
void main()
{
char a[]="●";
int i,j;
for(i=0;i<20;i++)
{
for(j=0;j<i;j++)
printf("\n");
puts(a);
Sleep(50);
system("cls");
}
printf("小球下落完毕!");
}

Ⅶ c语言,一个球从某高度h落下,每次落地后反弹回原来高度的一半,再落下。编程计算球在10次落地

根据你的题目和输出样式截图分析:

1、每次输出当前坠落的高度,及本次坠落后经过的距离总和

2、输出包含小数,因此高度及距离变量采用浮点数

3、递归/循环只执行10次

3、看你图上,输出浮点数小数不显示多余的0,因此打印格式要用%g而不是%f(最多保留6位)。

#include <stdio.h>

void drop(float height);

int main()

{

float height;

printf("初始高度:");

scanf("%f",&height);

drop(height);

return 0;

}

void drop(float height)

{

static int cnt=1;

static float distance=0;//每次坠落后球移动的距离总和

if(height>0){

distance+=height;

printf("第%d次高度%g ",cnt,height);

printf("第%d次距离%g ",cnt,distance);

if(cnt<10)

cnt++,distance+=height/2,drop(height/2);

else

cnt=1,distance=0;

}

}

Ⅷ C语言关于小球自由落体的循环设计

#include<stdio.h>
#include<math.h>
int main()
{
double a1=100,sum=0;
int i=0;
do
{
sum=sum+a1;
a1=0.5*a1;
sum=sum+a1;
i++;
}while(i<=9);
sum=sum+a1;
a1=0.5*a1
printf("%d\t%d\n",sum,a1);
return 0;
}

Ⅸ 求一个C语言小球自由落体的代码,要求超过100行

#include<stdio.h>

intmain(){
intcurve[31][37]={0};//图像保存在30*36矩阵内
doubleA,AM=30;//第一周期幅值
doublek=0.18;//幅值递减率
inti,x,y;
for(i=0;i<4;++i){//共画出4个周期
A=(1-i*k)*AM;
for(x=0;x<9;++x){//每个周期用9个点描画
y=-(int)(x*A*(x-8)/16.0);
curve[y][x+i*8]=1;
}
}
for(y=30;y>=0;--y){
for(x=0;x<37;++x){
if(curve[y][x])printf("+");
elseprintf(".");
}
printf(" ");
}
return0;
}

Ⅹ c语言课程设计"小球从空中落下,弹起,再落下,弹起幅度越来越小,直至停下"的动画

//环境:MicrosoftVisualC++6.0+EasyX
#include<graphics.h>
#include<conio.h>
#include<math.h>
#include<stdio.h>
#defineWIDTH100
#defineHEIGHT400
#defineRADIUS10
#defineTIMEDIV0.001
voidf(doubleheight,doubleair_k)
{
initgraph(WIDTH,HEIGHT,SHOWCONSOLE);
setaspectratio(1,-1);
setorigin(0,HEIGHT-RADIUS);
inty_pos=HEIGHT-RADIUS*2;
boolis_down=true;
doublev=0;
BeginBatchDraw();
doublex_frac=0,x_int;
for(;;)
{
Sleep((unsignedlong)(TIMEDIV*1000));
doublea=((is_down?1:-1)-air_k)*9.8;
doublex=(is_down?-1:1)
*(v*TIMEDIV+0.5*a*TIMEDIV*TIMEDIV)
*((HEIGHT-2*RADIUS)/height);
x_frac=modf(x+x_frac,&x_int);
y_pos+=(int)x_int;
if(is_down&&y_pos<=0)
{
is_down=false;
}
v+=a*TIMEDIV;
if(!is_down&&v<=0)
{
if(y_pos>0)is_down=true;
elsebreak;
}
cleardevice();
solidcircle(WIDTH/2,y_pos,RADIUS);
FlushBatchDraw();
if(kbhit()&&getch()=='')break;

}EndBatchDraw();
MessageBox(NULL,"小球已停止","balldown",0);
closegraph();
}
intmain()
{
do{
doubleheight,air_k;
printf("请输入下落高度(单位:米)(小数,大于0):");
scanf("%lf",&height);
printf("请输入空气阻力系数(即空气阻力与小球重力的比值)(小数,0~1):");
scanf("%lf",&air_k);
printf("按空格可重新开始");
f(height,air_k);
Sleep(1);
system("cls");
}while(1);
getch();
return0;
}