0% found this document useful (0 votes)
29 views

Sub Dim As Integer: Factorial Using Sub Procedure

This document contains code for calculating factorials and powers in Visual Basic. The factorial code uses a recursive Sub procedure to multiply all integers from 1 to the given number. The power code uses a Function to calculate the given base number raised to the given power by using the exponentiation operator. Both programs prompt the user to input numbers and display the output of the calculation.

Uploaded by

Aamir Hussain
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Sub Dim As Integer: Factorial Using Sub Procedure

This document contains code for calculating factorials and powers in Visual Basic. The factorial code uses a recursive Sub procedure to multiply all integers from 1 to the given number. The power code uses a Function to calculate the given base number raised to the given power by using the exponentiation operator. Both programs prompt the user to input numbers and display the output of the calculation.

Uploaded by

Aamir Hussain
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Factorial using Sub procedure:

Module Module1
Sub Main()
Dim num As Integer
Console.WriteLine("Enter number")
num = Console.ReadLine()
factorial(num)
Console.ReadLine()
End Sub
Sub factorial(ByVal a As Integer)
Dim c, d As Integer
c = 1
d = 1
Do While (c <= a)
d = d * c
c = c + 1
Loop
Console.WriteLine("The factorial of number

is {0}", d)

End Sub
End Module

Power fuction:
Module Module1
Sub Main()
Dim c, d, e As Integer
Console.WriteLine("Enter the Base number")
c = Console.ReadLine()
Console.WriteLine("Enter the Power of above")
d = Console.ReadLine
e = power(c, d)
Console.WriteLine("the power of number is ={0}", e)
Console.ReadLine()
End Sub
Function power(ByVal a As Integer, ByVal b As Integer) As Integer
Return a ^ b
End Function
End Module

You might also like