Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function SumListRecursive(numbers As List(Of Integer)) As Integer
- ' Base case: if the list is empty, return 0
- If numbers.Count = 0 Then
- Return 0
- Else
- ' Recursive case: add the first element to the sum of the rest of the list
- Dim firstElement As Integer = numbers(0)
- Dim remainingElements As List(Of Integer) = numbers.Skip(1).ToList()
- Return firstElement + SumListRecursive(remainingElements)
- End If
- End Function
Advertisement
Add Comment
Please, Sign In to add comment