功能:计算并输出下列多项式的值 S = 1 + 1/1! + 1/2! + 1/3! + ... + 1/n!
时间: 2023-10-09 07:09:45 浏览: 126
2022年浙江省二级C语言程序编写题库.doc
Sure, the answer is:
S = 1 + 1/1! + 1/2! + 1/3! + ... + 1/n!
To calculate the value of this polynomial, you can use a for loop to iterate through the number of terms in the polynomial, and accumulate the sum of each term. Here's the code in Python:
n = int(input("Enter the number of terms in the polynomial: "))
sum = 1
factorial = 1
for i in range(1, n+1):
factorial *= i
sum += 1/factorial
print("The value of the polynomial is:", sum)
阅读全文