这一题,真是觉得很郁闷,改了又改;最后勉强通过了。 总觉得它的题目很不标准,一开始那几个示例,让我产生了“数字后面不能有零”的感觉。结果当然是错了。百度一下,才知道然后有零也可以,唉,真是…… /* THE PROGRAM IS MADE BY PYY */ /*---------------------------------------------------------- http://acm.hdu.edu.cn/showproblem.php?pid=1012 u Calculate e Begin : 14:00 End : 15:21 ----------------------------------------------------------*/ #include <iostream> #include <iomanip> using namespace std; int main() { int i, factor[10], precision; double sum = 0; factor[0] = 1; for (i = 1; i < 10; i++) { factor[i] = i * factor[i - 1]; // cout << factor[i] << endl; } cout << "n e/n" << "- -----------/n" << "0 1/n" << "1 2/n" << "2 2.5/n"; sum = 2.5; for (i = 3; i < 10; i++) { sum += 1.0/factor[i]; cout << i << " " << setprecision(9) << fixed << sum << endl; } return 0; }