Cómo escribir código factorial en vb
1. Para implementación de declaraciones
Private Sub Command1_Click()
Dim s As Long, n As Integer, i As Integer
n = Val(Text1.Text)
s = 1
Para i = 1 To n
s = s * i
Siguiente i
Label4.Caption = Str(s)
End Sub
2. Implementación de la declaración Do While
Private Sub Command1_Click( )
Dim s Mientras, n Como Entero, i Como Entero
n = Val(Text1.Text)
s = 1
i = 1
Hacer mientras i <= n
s = s * i
i = i + 1
Bucle
Label4.Caption = Str(s)
End Sub
Información ampliada:
Los resultados del factorial de 1~10 son los siguientes:
1!=1
2!=2*1=2
3!=3*2*1=6
4!=4*3*2*1=24
5!=5*4*3*2*1=120
6!=6*5 *4*3 *2*1=720
7!=7*6*5*4*3*2*1=5040
8!=8*7*6 *5*4 *3*2*1=40320
9!=9*8*7*6*5*4*3*2*1=362880
10! =10*9 *8*7*6*5*4*3*2*1=3628800