Write a mobile app (using TouchDevelop) that calculates
the sum (which computes e×) of n + 1 terms as
sum = 1 + x/ 1! + /2! +
/ 3! +
/4! + …
Values x and n should be read (prompted to enter). Calculate each sequential term base on the previous one to get the best calculation performance (so, the next one = the previous term * (x / i) where i the current control variable – index). Don’t use the math function. Use only one loop. The output should be in the table format as follows (remember to use the reverse wall order shown in class):
x = ?, n = ?
iteration # termValue sum
…
Example:
x = 1, n = 2
iteration # termValue sum
1 1 2
2 0.5 2.5
e× = 2.71828…, where x = 1
Each row corresponds to values in each iteration except the last row which should give the final result in the text box (see p.38 ch3 of our text [3] and also the last exercise in class). A very last line of the output should give the return value of e× from the formula exp(x : Number) : Number (see p.186 of our text).
Test for x = 1, n = 5 and n = 10 – the expected result should be better for n = 10 and you will expect the sum around 2.71828…. Next test for x = 2, n = 5, and n = 10.


0 comments