本文目錄一覽:
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(height0){
distance+=height;
printf(“第%d次高度%g\n”,cnt,height);
printf(“第%d次距離%g\n”,cnt,distance);
if(cnt10)
cnt++,distance+=height/2,drop(height/2);
else
cnt=1,distance=0;
}
}
C語言 圖形程序—小球反彈
44行語法錯誤。
if(((x+R)=X2(y-R)=Y1)||(x-R)=X1(y-R)=Y1)||((x+R)=X2(y+R)=Y2)||((x-R)=X1(y+R)=Y2))
if 這麼多括弧容易混
這裡少一個後括弧,下修改:
if(((x+R)=X2(y-R)=Y1)||((x-R)=X1(y-R)=Y1)||((x+R)=X2(y+R)=Y2)||((x-R)=X1(y+R)=Y2))
C語言小球落地反彈
題目給出的答案不正確。
#include “stdio.h”
int main()
{float h,s,x;
int i,n;
scanf(“%f%d”,h,n);
for(i=0;in;i++)
{x=(int)(h*100+0.5)/100.0;
s+=x;
h/=2;
}
printf(“%.2f\n%.2f\n”,s,h);
return 0;
}
C語言編寫程序解決小球下落反彈問題用
#include stdio.h
main()
{
float sum=0;
int i=0;
float height=100;
sum+=height;
while(i10)
{
height=height/2;
sum+=2*height;
i++;
}
printf(“總長度:%f 第10次跳%f米”,sum,height);
}
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/254957.html