This part :Makes me think you have two variables. One's the sum so far. The other is X = 1/n! for the previous value of n. To get the next sum, domeaning that one part of the variable will hold the result of the calculation which will be x=1.00000000~ and the other will hold the actual sum up until now which is e=2.000000~
That is, each x[N] isn't a discrete set of digits that gets mushed together to form the final output, it's then next value you add to sum. Each x[N] has digits which contribute to change many of the digits instead of your idea that x is digits 1-5 after the decimal point and the other x values have nothing at all to do with them.Code:X /= n; sum += other; n += 1
x = 1 = 1.00000
x = 1 = 1.00000
x = 1/2 = 0.50000
x = 1/6 = 0.16667
x = 1/24 = 0.04167
Note how both x and x change the integer part of the sum, and x and x both contribute to the digit right after the decimal point (the tenth's place) while x and x both contribute to change every digit in the fractional part (.16666 + 0.4167 = .20833 so every digit is different than before). You can't just line up x.xxxx and get 1.100000500001666704167, you have to add up each of the terms to get the final result.
To say it a different way : read through the assignment and notice it isn't telling you to keep an array of X values, just one. It's telling you to keep track of exactly two values : the sum so far and 1/N! for the current value of N. Why do you need an array of 5 values plus a sum to hold two items?
Also, does it specifically say 30-35 digits, or 30-35 iterations of the loop (i.e. N can go up to 30)? There's a big difference between the two. There's no reason to assume each iteration series will give you exactly one digit of accuracy. That's easy to see since doing 1 iteration gives you 1 as the result, so you need two iterations to get the first digit correct. If you're supposed to run 30 iterations to get 15 digits that'll fit in a double - no need for arbitrary precision numbers.