你得到了一系列的1/1!+2/2! + 3/3! + 4/4! +…….+ 不!,求出直到第n项的级数之和。
null
例如:
Input :n = 5 Output : 2.70833 Input :n = 7 Output : 2.71806
# Python code to find smallest K-digit # number divisible by X def sumOfSeries(num): # Computing MAX res = 0 fact = 1 for i in range ( 1 , num + 1 ): fact * = i res = res + (i / fact) return res n = 5 print ( "Sum: " , sumOfSeries(n)) # Code contributed by Mohit Gupta_OMG <(0_o)> |
输出:
Sum: 2.70833
请参阅完整的文章 求一系列1/1之和的程序!+2/2! + 3/3! + 4/4! +…….+ 不! 更多细节!
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END