chamsi09

Untitled

Nov 15th, 2024
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.60 KB | None | 0 0
  1. Module Module1
  2.     Sub Main()
  3.         Dim base As Integer = 2
  4.         Dim exponent As Integer = 3
  5.         Dim result As Integer = Power(base, exponent)
  6.         Console.WriteLine(base & "^" & exponent & " = " & result)
  7.     End Sub
  8. Function Power(base As Integer, exponent As Integer) As Integer
  9.         ' Base case: any number raised to the power of 0 is 1
  10.         If exponent = 0 Then
  11.             Return 1
  12.         Else
  13.             ' Recursive case: multiply base by the result of Power(base, exponent - 1)
  14.             Return base * Power(base, exponent - 1)
  15.         End If
  16.     End Function
  17. End Module
  18.  
Advertisement
Add Comment
Please, Sign In to add comment