Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Module Module1
- Sub Main()
- Dim base As Integer = 2
- Dim exponent As Integer = 3
- Dim result As Integer = Power(base, exponent)
- Console.WriteLine(base & "^" & exponent & " = " & result)
- End Sub
- Function Power(base As Integer, exponent As Integer) As Integer
- ' Base case: any number raised to the power of 0 is 1
- If exponent = 0 Then
- Return 1
- Else
- ' Recursive case: multiply base by the result of Power(base, exponent - 1)
- Return base * Power(base, exponent - 1)
- End If
- End Function
- End Module
Advertisement
Add Comment
Please, Sign In to add comment