A factorial program that I wrote using Microsoft Visual Basic .NET to solve for the factorial of the number. The code is very easy to understand I create a function called factorial which uses recursion algorithm to solve the factorial of the given number by our user.
Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com
My mobile number here in the Philippines is 09173084360.
Sample Program Output
Program Listing
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Label2.Visible = False
End Sub
Private Function Factorial(ByVal inputval As Integer) As Integer
Dim f As Integer
Factorial = 1
For f = 2 To inputval
Factorial = Factorial * f
Next
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Label2.Visible = True
Dim myNumber1, mynumber2 As Integer
myNumber1 = Val(TextBox1.Text)
mynumber2 = Factorial(Val(TextBox1.Text))
Label2.Text = "The factorial value of " & myNumber1 & _
" is " & mynumber2 & "."
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Label2.Visible = False
TextBox1.Text = ""
Label2.Text = ""
Label2.Text = ""
TextBox1.Focus()
End Sub
End Class
No comments:
Post a Comment