dim i as long dim curh as single i=0 curh=10.0 do while curh>=0.01 curh=curh*0.5 i=i+1 loop msgbox i
...还有路程改下: dim i as long dim curh as single,rl as single i=0 curh=10.0 rl=curh do while curh>=0.01 curh=curh*0.5 i=i+1 rl=rl+curh*2 loop msgbox format(i) & "次," & format(rl) & "米"
...还有路程改下: dim i as long dim curh as single,rl as single i=0 curh=10.0 rl=curh do while curh>=0.01 curh=curh*0.5 i=i+1 rl=rl+curh*2 loop msgbox format(i) & "次," & format(rl) & "米" ...还有路程改下: dim i as long dim curh as single,rl as single i=0 curh=10.0 rl=curh do while curh>=0.01 curh=curh*0.5 i=i+1 rl=rl+curh*2 loop msgbox format(i) & "次," & forma……
ya zhe shi shenme
设反弹了N次,有: 因为反弹一次为10的1/2,两次为:(10*1/2)*1/2 =10/4则: 10*(1/(2*N)) = 0.001 N = 1/(0.001/10*2) N = 500次 小球走过的路径是:(10*1/2)+ (10*/(2*2))+ (10*/2*3)+.........(10/2*500)+10 小球路径我的算法好像麻烦点,暂时没想到更好的算法,谁有高招继续。
#include <iostream> using namespace std;int main() { float a = 10.0; float sum = 10.0; do { a=a/2; sum+=2*a; } while(a>=0.01); cout << sum <<endl; system("pause"); return 0; }
#include <iostream> using namespace std;int main() { float a = 10.0; float sum = 10.0; do { a=a/2; sum+=2*a; } while(a>=0.01); cout << sum <<endl; system("pause"); return 0; }
试试这个 ftp://ldong.net/xyz/ball.rar
int curH = 10;//当前高度 int sun = curH;//总路程 while(curH > 0.01) { curH = curH/2; sun = sum+curH; }System.out.println("总路程是"+sum+"米");
...还有路程改下: dim i as long dim curh as single,rl as single i=0 curh=10.0 rl=curh do while curh>=0.01 curh=curh*0.5 i=i+1 rl=rl+curh*2 loop msgbox format(i) & "次," & format(rl) & "米"
ddddddddddddddddddddddddddddddddddddddddd
public static void main(String[] args) { double height =10; //高度 int count = 0; //次数 double s=0; //路程 while(height>=0.01){ count++; if(count==1){ s += height; }else{ s += height*2; } height = height*0.5;
float high = 10; float sum = 0; int num = 0; while (high >= 0.01) { num++; sum = sum + high + high / 2; high = high / 2; } Console.WriteLine("球总共落地"+num+"次,经过的路程为"+ sum); Console.ReadLine();这样就可以拉
大侠推荐的帖子还是要顶的,题目似乎不难,计算过程有点意思 Public Function M_fn(n As Double) As Double Static nn As Double If n > 0.01 Then nn = nn + 1 M_fn = (n + M_fn(n / 2)) End If End Function 运行结果 M_fn(10)=19.98046875谁分析下这个函数有什么问题?好像漏掉了10?
dim curh as single
i=0
curh=10.0
do while curh>=0.01
curh=curh*0.5
i=i+1
loop
msgbox i
dim i as long
dim curh as single,rl as single
i=0
curh=10.0
rl=curh
do while curh>=0.01
curh=curh*0.5
i=i+1
rl=rl+curh*2
loop
msgbox format(i) & "次," & format(rl) & "米"
=
10 + 20 * (1/2 + 1/4 + 1/8 + ...1/2^n) 很显然 10 + 20*1 = 30 M一个纯数学问题。 没必要用程序。就象我们去算 1+2+3+ .. N 一样。 算法第一。
dim i as long
dim curh as single,rl as single
i=0
curh=10.0
rl=curh
do while curh>=0.01
curh=curh*0.5
i=i+1
rl=rl+curh*2
loop
msgbox format(i) & "次," & format(rl) & "米"
...还有路程改下:
dim i as long
dim curh as single,rl as single
i=0
curh=10.0
rl=curh
do while curh>=0.01
curh=curh*0.5
i=i+1
rl=rl+curh*2
loop
msgbox format(i) & "次," & forma……
因为反弹一次为10的1/2,两次为:(10*1/2)*1/2 =10/4则:
10*(1/(2*N)) = 0.001
N = 1/(0.001/10*2)
N = 500次
小球走过的路径是:(10*1/2)+ (10*/(2*2))+ (10*/2*3)+.........(10/2*500)+10
小球路径我的算法好像麻烦点,暂时没想到更好的算法,谁有高招继续。
int num=0;//次数;
double hight=10.0;//高度
double total=0;//总路程
while(hight>=0.01)
{
total+=hight;
hight=hight/2.0;
num++;
}
printf("num=%d,total=%d",num,total);
using namespace std;int main()
{
float a = 10.0;
float sum = 10.0;
do
{
a=a/2;
sum+=2*a;
}
while(a>=0.01);
cout << sum <<endl;
system("pause");
return 0;
}
using namespace std;int main()
{
float a = 10.0;
float sum = 10.0;
do
{
a=a/2;
sum+=2*a;
}
while(a>=0.01);
cout << sum <<endl;
system("pause");
return 0;
}
int sun = curH;//总路程
while(curH > 0.01) {
curH = curH/2;
sun = sum+curH;
}System.out.println("总路程是"+sum+"米");
dim i as long
dim curh as single,rl as single
i=0
curh=10.0
rl=curh
do while curh>=0.01
curh=curh*0.5
i=i+1
rl=rl+curh*2
loop
msgbox format(i) & "次," & format(rl) & "米"
public static void main(String[] args) { double height =10; //高度
int count = 0; //次数
double s=0; //路程
while(height>=0.01){
count++;
if(count==1){
s += height;
}else{
s += height*2;
}
height = height*0.5;
System.out.print("第"+count+"次反弹后的高度:"+height+" ");
System.out.println("第"+count+"次落地前的路程:"+s+" ");
}
System.out.println("反弹的次数:"+count);
System.out.println("球走的路程:"+s);
}
第1次反弹后的高度:5.0 第1次落地前的路程:10.0
第2次反弹后的高度:2.5 第2次落地前的路程:20.0
第3次反弹后的高度:1.25 第3次落地前的路程:25.0
第4次反弹后的高度:0.625 第4次落地前的路程:27.5
第5次反弹后的高度:0.3125 第5次落地前的路程:28.75
第6次反弹后的高度:0.15625 第6次落地前的路程:29.375
第7次反弹后的高度:0.078125 第7次落地前的路程:29.6875
第8次反弹后的高度:0.0390625 第8次落地前的路程:29.84375
第9次反弹后的高度:0.01953125 第9次落地前的路程:29.921875
第10次反弹后的高度:0.009765625 第10次落地前的路程:29.9609375
反弹的次数:10
总路程:29.9609375
double hight=10.0;//高度
double total=0;//总路程
while(hight>=0.01)
{
total+=hight;
hight=hight/2.0;
num++;
}
printf("num=%d,total=%d",num,total);
float sum = 0;
int num = 0;
while (high >= 0.01)
{
num++;
sum = sum + high + high / 2;
high = high / 2;
}
Console.WriteLine("球总共落地"+num+"次,经过的路程为"+ sum);
Console.ReadLine();这样就可以拉
你漏了最后一次下落
这是两个等比数列的问题,
第一个等比数列的a1=10、比例:0.5
第二个等比数列的a1=5、比例:0.5
要求所经过的路径,实际上就是两个等比数列数据的和,理论上等比数列前N项的和:Sn=a1(1-(0.5)^n)/(1-q)在n趋于无穷大时,Sn=a1/(1-0.5)
所以,球经过的路程:10/(1-0.5)+5/(1-0.5)=20+10=30
#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
#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
Public Function M_fn(n As Double) As Double
Static nn As Double
If n > 0.01 Then
nn = nn + 1
M_fn = (n + M_fn(n / 2))
End If
End Function
运行结果 M_fn(10)=19.98046875谁分析下这个函数有什么问题?好像漏掉了10?