Q3 Write a window application in VB.NET to find out the factorial of given number and input should be taken from the user.

We know that factorial means if we input number 5 then we have to calculate this number like 1*2*3*4*5 and then the final calculation will be the factorial. The form is as follows:


Here textbox accept number and first it will be converted into integer number and assigned to the variable n. the code is as follows:

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim n, i As Integer
Dim fact As Integer = 1
n = Convert.ToInt32(TextBox1.Text)
For i = 1 To n
fact = fact * i
MessageBox.Show("Factorial is " & fact, "Factorial")

End Sub
End Class

Here we have used for loop. Here we used condition i To n means this loop will be continue till the ith value will not be equal to the entered number. Inside the loop, we have used fact*I and it is assigned to fact after that we have incremented the value of variable I by 1. This loop will be continued till the condition will not become false. The output is as follows: