English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Please give a the codes in the program that will calculate the factorial of a certain number! For example, "5!". The computer will mulitply 5 by 4 by 3 by 2 and by 1. Another example, "8". The pragam will multiply 8 by 7 by 6 by 5 by 4 by 3 by 2 by 1. Get the idea?! It don't have to type the factorial sign "!" in the text box. You just type the number and then click the command button "calculate" or whatever name you want! I need it ASAP! Please!... Its our computer lesson! HELP... All the geniuses out there please help!

2007-02-22 22:35:41 · 2 answers · asked by Rinko_Sano 2 in Computers & Internet Programming & Design

2 answers

Function Factorial(ByVal number As Long) As Long
If number <= 1 Then
Return (1)
Else
Return number * Factorial(number - 1)
End If
End Function 'Factorial

Notice that the function contains a call to itself.

An example of code which calls the factorial function is as follows:

Private Sub Button1_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Dim StartValue As Integer = _
Convert.ToInt32(txtStartValue.Text)
Dim I As Integer
txtResult.Text = ""
For I = 0 To StartValue
txtResult.Text &= I & "! = " & _
Factorial(I) & vbCrLf
Next 'I
End Sub

2007-02-22 22:41:55 · answer #1 · answered by burhan_ace 3 · 0 0

Its very simple as this.


Private sub Factorial_Click()

f = 1
for i = 1 to val (textFact) step 1
f = f * i
next

End sub

2007-02-23 06:51:43 · answer #2 · answered by Rocks 2 · 0 0

fedest.com, questions and answers