wes d2a2ba9e15 first commit | před 4 roky | |
---|---|---|
.. | ||
README.md | před 4 roky | |
code.cpp | před 4 roky | |
unitTest.cpp | před 4 roky |
by Matt tags: recursion, math, numbers, language_fundamentals
Write a function that finds the sum of the first n natural numbers. Make your function recursive. Examples sum(5) ➞ 15 // 1 + 2 + 3 + 4 + 5 = 15 sum(1) ➞ 1 sum(12) ➞ 78 Notes Check the Resources tab for info on recursion.
Write a function that finds the sum of the first n
natural numbers. Make your function recursive.
sum(5) ➞ 15
// 1 + 2 + 3 + 4 + 5 = 15
sum(1) ➞ 1
sum(12) ➞ 78
Check the Resources tab for info on recursion.