|
![]() | 作者: afan271314 [afan271314]
![]() |
登录 |
题目:一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在 第10次落地时,共经过多少米?第10次反弹多高? 1.程序分析:见下面注释 2.程序源代码: main() { float sn=100.0,hn=sn/2; int n; for(n=2;n<=10;n++) { sn=sn+2*hn;/*第n次落地时共经过的米数*/ hn=hn/2; /*第n次反跳高度*/ } printf("the total of road is %f\n",sn); printf("the tenth is %f meter\n",hn); } 原标题:各位大哥路过看一下这个对吗 [此贴被 286(unique) 在 02月17日16时11分 编辑过] |
地主 发表时间: 04-02-15 20:16 |
![]() | 回复: xiean [xiean] ![]() |
登录 |
int main() { float sn = 100.0; int n; /* 下面是 n 大于等于2时的求解 */ printf("the total of road is %f\n", sn*3 - sn/pow(2,(n-1))); printf("the tenth is %f meter\n", sn/pow(2,n)); } 典型的数学模型题就不要用遁环了,后续的是可测的值,那么可以用方程式来求解 n = 2, 300 - 100/2^1 = 250, 100/2^2 = 25 n = 3, 300 - 100/2^2 = 275, 100/2^3 = 12.5 n = 4, 300 - 100/2^3 = 287.5, 100/2^4 = 6.25 .... n = 8, 300 - 100/2^7 = 299.21875, 100/2^8 = 0.390625 ---------------------------------------- 刚才把平方函数记错了,记成数学标记^了,昏 ![]() [此贴被 邪安(xiean) 在 02月16日15时35分 编辑过] |
B1层 发表时间: 04-02-16 14:58 |
![]() | 回复: xiean [xiean] ![]() |
登录 |
感谢猪头 ND 帮助,提供 pow 一用 ![]() [root@vm root]# cat test.c #include <math.h> #include <stdio.h> int main() { float sn = 100.0; int n = 10; printf("the total of road is %f\n", sn*3 - sn/pow(2,(n-1))); printf("the tenth is %f meter\n", sn/pow(2,n)); } [root@vm root]# gcc -lm -o test test.c [root@vm root]# ./test the total of road is 299.804688 the tenth is 0.097656 meter [root@vm root]# |
B2层 发表时间: 04-02-16 15:36 |
![]() | 回复: lida1818 [lida1818] ![]() |
登录 |
??? 不是吧?我怎么算出是 the total of road is 299.60937? ![]() ![]() the tenth is 0.1953125 meter ![]() 你错还是我错? ![]() [此贴被 烟雨平生(lida1818) 在 02月17日15时37分 编辑过] |
B3层 发表时间: 04-02-17 15:34 |
![]() | 回复: xiean [xiean] ![]() |
登录 |
100 100 1 50 200 2 25 250 3 12.5 275 4 6.25 287.5 5 3.125 293.75 6 1.5625 296.875 7 0.78125 298.4375 8 0.390625 299.21875 9 0.1953125 299.609375 10 0.09765625 299.8046875 看明白没?你吓我一跳。。。上面的数值是手工算的。。。,记得 100 米的时候,不算是落地的。。。你算的是第9是落地 [此贴被 邪安(xiean) 在 02月17日17时14分 编辑过] |
B4层 发表时间: 04-02-17 17:08 |
![]() | 回复: sniper167 [sniper167] ![]() |
登录 |
sn*3 - sn/pow(2,(n-1)) 怎麽是共经过多少米? |
B5层 发表时间: 04-02-17 18:19 |
![]() | 回复: lida1818 [lida1818] ![]() |
登录 |
邪安 [xiean] 我想我们都错了,我看了你的贴子,又仔细看了看题。你看看我的程式和结果: #include <math.h> #include <stdio.h> main() { float sn=100.0,hn=0; int n; for(n=0;n<=9;n++) { sn=sn+2*hn; printf("n=%d\n",n); printf("sn=%f\n",sn); hn=100*(pow(0.5,(n+1))); printf("hn=%f meter\n",hn); } } 运行结果:(注意是: 第10次落地时,共经过多少米? ) n=0 第一次 sn=100.000000 hn=50.000000 meter n=1 sn=200.000000 hn=25.000000 meter n=2 sn=250.000000 hn=12.500000 meter n=3 sn=275.000000 hn=6.250000 meter n=4 sn=287.500000 hn=3.125000 meter n=5 sn=293.750000 hn=1.562500 meter n=6 sn=296.875000 hn=0.781250 meter n=7 sn=298.437500 hn=0.390625 meter n=8 sn=299.218750 hn=0.195312 meter n=9 sn=299.609375 hn=0.097656 meter |
B6层 发表时间: 04-02-17 18:47 |
![]() | 回复: deathmask [deathmask] ![]() |
登录 |
#include "math.h" #include "stdio.h" void main() { float cn=100,temp=100; printf("最后落地是%f\n",cn*pow(0.5,10)); for (int i=1;i<=10;i++) { temp=temp+cn; cn=cn/2; } printf("一共落地%f次\n",temp); } 偶是这样算的,看起来好象差不多 邪安我想问个问题就是你那个sn*3 是怎样得出的呢 [此贴被 deathmask(deathmask) 在 03月13日21时30分 编辑过] [此贴被 deathmask(deathmask) 在 03月13日21时37分 编辑过] |
B7层 发表时间: 04-03-13 21:28 |
![]() | 回复: tetley [tetley] ![]() |
登录 |
邪安的程序n是把从50米落下时算作1吧。 我想的3Sn是Sn + 2Sn, 第一个Sn 是从100 米落下, 是一种特殊情况。 然后2Sn - Sn/pow(2,(n-1)) 是用来计算由50米开始, 因为 上升=下降 。 我解释得不好。 还有, 学编程序用到了这些么? 有什么用呀? ![]() |
B8层 发表时间: 04-03-16 04:00 |
|
20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon
粤ICP备05087286号