Question
Define a recursive function sumdown $::$ Int $\rightarrow$ Int that returns the sum of the non-negative integers from a given value down to zero. For example, sumdown 3 should return the result $3+2+1+0=6$.
Step 1
In this case, the base case is when the input value is 0. When the input value is 0, we don't need to do any more calculations and can simply return 0. The recursive case is when the input value is greater than 0. In this case, we want to add the current value Show more…
Show all steps
Your feedback will help us improve your experience
Nick Johnson and 95 other educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Give a recursive algorithm for finding the sum of the first n positive integers.
Induction and Recursion
Recursive Algorithms
Give a recursive algorithm for computing $n x$ whenever $n$ is a positive integer and $x$ is an integer, using just addition.
Let $F$ be the function such that $F(n)$ is the sum of the first $n$ positive integers. Give a recursive definition of $F(n) .$
Recursive Definitions and Structural Induction
Transcript
Watch the video solution with this free unlock.
EMAIL
PASSWORD