I need help with 2 things, I want enter 20 numbers in inputbox and say what is the greater and lesser in the end with msgbox.
and the other is, enter a number in a inputbox and calculate his factorial.
Thanks a i am lern vb now. English too ;p
Printable View
I need help with 2 things, I want enter 20 numbers in inputbox and say what is the greater and lesser in the end with msgbox.
and the other is, enter a number in a inputbox and calculate his factorial.
Thanks a i am lern vb now. English too ;p
Welcome to the forums. :wave:
What code do you have so far?
Thanks. ;)
Factorial i did this.
------------------------------------------------------------------------Code:'// Declaração e Inicialização de Variáveis
Dim valor As Integer = 0
Dim resposta As String
Dim temp As Double
Dim fatorial As Double
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Do
'// Entrada de Dados
valor = InputBox("Entre com o valor a ser calculado:")
If valor < 0 Then
MsgBox("Entre apenas com numeros positivos")
End If
'// Processamento de Dados
If valor = 0 Then
fatorial = 1
Else
temp = valor
Do Until valor <= 1
valor = valor - 1
temp = temp * valor
Loop
fatorial = temp
End If
'// Saida dos Dados
MsgBox("O fatorial é " & fatorial)
'// Perguntar se Quer Continuar
resposta = InputBox("Deseja Continuar S/N?:")
resposta = resposta.ToUpper
Loop Until (resposta.Equals("N"))
Close()
End Sub
End Class
I can´t find a way to do if I enter a negative value he restart the program.
The other i don´t have a clue yet...
]
To get the factorial of a number you could just do:
vb Code:
Private Sub Form_Load() MsgBox Factorial(5) End Sub Private Function Factorial(ByVal Number As Long) As Long If Number = 1 Then Factorial = 1 Else Factorial = Number * Factorial(Number - 1) End If End Function
Moved.