Ⅰ 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;
}