7,763
社区成员
发帖
与我相关
我的任务
分享
VFP代码:
clear
l=10
s=10
X=0
Do While l>=0.01
X=X+1
s=s+l*0.5
l=l*0.5
? X &&计算次数
? s &&计算机总路程
? l &&计算最后高度
Enddo
最后结果:
X=10
S=19.9902343750
L=0.0097656250
如加上最后回落的话就是S+L
clear
l=10
s=10
Do While l>=0.01
s=s+l*0.5
l=l*0.5
? s
? l
Enddo
vfp代码!最终结果如下:
S=19.9902343750
L=0.0097656250
M_fn = n + (n/2) + M_fn(n / 2)
#include <stdio.h>
#define H 10
void main()
{
float distance;
float high;
int count;
count = 0;
high = H;
while(high > 0.01)
{
distance +=high;
count++;
high = high/2;
}
distance += high;
printf("The distance is:%f\n",distance);
printf("The count is:%d\n",count);
}
The distance is:19.990234
The count is:10
#include <stdio.h>
#define H 10
void main()
{
float distance;
float high;
int count;
count = 0;
high = H;
while(high > 0.01)
{
distance +=high;
count++;
high = high/2;
}
printf("The distance is:%f\n",distance);
printf("The count is:%d\n",count);
}
The distance is:19.980469
The count is:10