A sequence is a list of numbers that are calculated based on a certain rule. For instance, the progression described by the rule An = 2 ∗ n results in the numbers: 0 2 4 6 8 10 ··· 2 ∗ n. The sum of this sequence can be calculated as Sn = 0+2+4+6+8+10+···+2 ∗ n. Write a function that takes as input the number n and calculates the sum of the sequence up to the nth term (inclusive) for each sequence shown below.
• An = 1 n 2 , for n > 0 such that Sn = 1 1 + 1 4 + 1 9 + 1 16 +···+ 1 n 2 .
• An = (−1) n (n+1)! , for n ≥ 0 such that Sn = 1 1 − 1 2 + 1 6 − 1 24 +···+ (−1) n (n+1)!
Note: By default, Racket does not use floating point notation to do arithmetic. To force it to use floating point you have to write a #i in front of at least one number that is involved in the computation. You can also write your numbers as a floating point by writing 1.0 instead of 1.
It is not mentioned in question ,In which language you want
code, so I prefered python , over all other programming languages,
beause python is very popular and very common.
if you want solution in any other language,then pls comment ...i
will provide you solution asap :)
Get Answers For Free
Most questions answered within 1 hours.