Exercise 4-7 Find the approximate value of e (15 points) The
natural constant e can be approximated by the series 1+1/1!+1/2!+...+1/n!+... This question requires that for a given non-negative integer n, find the sum of the first n+1 terms of the series.
Input format:
Enter a non-negative integer n (≤1000) in the first line of input.
Output format:
Output the partial sum value in one line, with eight digits after the decimal point.
Input sample:
10
Output sample:
2.71828180
#include<stdio.h>
int main()
{
int n,i,j;
double e=1.0,sum;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum=1;
for(j=1;j<=i;j++)
{
sum*=j;
}
sum=1.0/sum;
e+=sum;
}
printf("%.8lf",e);
}