filmov
tv
Program to Calculate Sum of 1+2+...+N (Loop v.s Recursion)

Показать описание
In this video, I will show you how to calculate the sum of 1+2+3+...+N using a Python program with a loop, and then I will show you how to also calculate the sum of series using recursion.
What is recursion? Recursion is a function that calls upon itself. Here, we write a function that calls upon itself and to find the sum of a series using recursion. While it is easy to use a for loop or while loop to do this, it is important that you understand these recursion steps to have a strong foundation to learn more complex recursive algorithm in the future.
You could also calculate the sum from 1 to N or N to 1 using this formula: n(n+1)/2, assuming the steps is 1 meaning it is the series of i=1 to i=n of i.
In the next video, I will show you how to print a list or an array using recursion.
LIKE & SUBSCRIBE:
MY EQUIPMENT:
✅Camera: Samsung Galaxy J7
✅Editing Software: Shotcut
What is recursion? Recursion is a function that calls upon itself. Here, we write a function that calls upon itself and to find the sum of a series using recursion. While it is easy to use a for loop or while loop to do this, it is important that you understand these recursion steps to have a strong foundation to learn more complex recursive algorithm in the future.
You could also calculate the sum from 1 to N or N to 1 using this formula: n(n+1)/2, assuming the steps is 1 meaning it is the series of i=1 to i=n of i.
In the next video, I will show you how to print a list or an array using recursion.
LIKE & SUBSCRIBE:
MY EQUIPMENT:
✅Camera: Samsung Galaxy J7
✅Editing Software: Shotcut