Computer Science, asked by BrainlyProgrammer, 26 days ago

Topic: Recursion
Using recursion, write a program that returns the sum of the following series.
\tt 0+2+18+72+... + nth \: term
_
#Challenge​

Answers

Answered by anindyaadhikari13
17

Hint:

For this series:

\rm\longrightarrow n^{th}\ term=\dfrac{[n(n-1)]^{2}}{2}

The Co‎de:

The problem is solved using Python.

f=lambda x: (x*(x-1))**2//2   # defines f(x)

sum=lambda n:f(n)+sum(n-1) if n else 0   # defines sum(n)

n=int(input('Enter limit: '))  # accepts limit.

print(f'Sum of first {n} terms of the series is {sum(n)}.')   # displays sum.

Algorithm:

The sum can be calculated using the following recursive algorithm.

\rm\longrightarrow sum(n) = \begin{cases}\rm f(n)+sum(n-1), \ \ n>0\\ \rm0,\ \ n=0\end{cases}

Where f(n) denotes the nᵗʰ term of the series, given by:

\rm\longrightarrow f(n)=\dfrac{[n(n-1)]^{2}}{2}

See attachment for output.

Attachments:

anindyaadhikari13: Thanks for the brainliest :)
Similar questions