作者suhorng ( )
站内Programming
标题Re: [问题] e^x相关题目
时间Wed Jul 17 12:44:33 2013
※ 引述《peggypiano (大N)》之铭言:
: 这一题的题目我看不太懂QQ
: 有人能帮忙解释一下吗?
: 我就我所理解的先打出来,麻烦帮忙指正了谢谢><
: ------
: The value e^x can be approximated by the sum
: 1 + x^1/1! + x^2/2! + x^3/3! +.........+ x^n/n!
: Write a program that takes a value x as input and outputs this sum for n
: taken to be each of the values 1 to 100.
: //Q1:让使用者可以输入x,并分别输出n=1(即1+x^1/1!),..,n=100(即1+...+x^100/100!)
: 还是 输出n=1(即x^1/1!), n=2(即x^2/2!),...,n=100(即x^100/100!)呢?
第一个解释 (1+...+x^n/n! for n=1,2,...,100)
: The program should also output e^x calculated using the predefined
: function exp. The function exp is a predefined function such that exp(x)
: returns an approximation to the value e^x.
: //还要输出e^x的值(使用者输入之x, n为无限大)(收敛值?)
: //Q2: predefined function exp,是指要我先写一个exp()出来吗?
: The function exp is in the library with the header file cmath. Your program
: should repeat the calculation for new values of x until the user says she or
: he is through.
: //Q3:这句我超不懂QQ 是跟我说在<cmath>里有exp可以参考的意思吗 囧
: 第2句我不懂他的意思,不是已经让user输入过x了吗@_@ repeat the calculation
: 是? new value of x是? 直到user怎样呢QQ?
Q2跟Q3是同一个问题
就是叫你顺便用内建的exp函式算值并输出, prototype定义在 cmath 里面
include就可以用了
"Your program should repeat ..."
这个跟 Q1 Q2 Q3 都无关 意思是你写的程式应该要
while (the user input a new `x` value)
calculate e^x partial sum for n=1,2,...,100
and calculate exp(x)
: Use variables of type double to store the factorials or you are likely to
: produce integer overflow (or arrange your calculation to avoid any direct
: calculation of factorials).
: //Q4: 用double变数去储存factorials(n!的值吗?),不然可能会有整数
: 变数漏掉浮点数、无法进行有浮点数的除法计算的问题? 或是避免计算中直接去
: 计算factorials??这是什麽意思呢QQ
对 用douuble去存 n! 的值
不然 n! 会太大, int 存不下, 会跑出错的结果(undefined behavior)
或是计算中避免直接计算 n!, i.e. 避开这样的步骤
1. 计算 a := x^n
2. 计算 b ;= n!
3. 然後计算 c := a/b
懒得避开的话就用 double 来存 n!
: 100 lines of output might not fit comfortably on
: your screen. Output the 100 output values in a format that will fit all
: 100 values on the screen. For example, you might output 10 lines with 10
: values on each line.
: 请我每10行输出10个值?
: 麻烦大家帮忙看看了 谢谢QQ
每一行输出 10 个值, 共 10 行(100个值)
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.166.48.166
※ 编辑: suhorng 来自: 118.166.48.166 (07/17 12:45)
1F:推 peggypiano:太谢谢你了!!!! 1.175.137.110 07/17 13:36
2F:→ peggypiano:我想再问请user输入新的x是指和Q1是同 1.175.137.110 07/17 13:37
3F:→ peggypiano:一次吗 1.175.137.110 07/17 13:37
4F:→ peggypiano:所以题目的整体要求应该是: 1.175.137.110 07/17 13:37
5F:→ peggypiano:1. 请user输入x 2.列出n=1~100的e^x值 1.175.137.110 07/17 13:39
6F:→ peggypiano:3.引用exp()去求出e^x(n无限)的收敛值? 1.175.137.110 07/17 13:41
7F:→ suhorng:是 是同一个 而且要不断loop 140.112.16.131 07/17 17:51
8F:→ peggypiano:谢谢你喔!!!!:))) 1.175.137.110 07/19 12:21