Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class Form1
- Private Sub Command1_Click()
- Dim n As Integer 'Number of rows
- Dim i, j As Integer 'Counters
- n = Val(TextBox1.Text)
- For i = 0 To n - 1
- 'Label1.Text += (Space(n - i)) add this if label is not centered
- For j = 0 To i
- Label1.Text += (Trim(Str(nCr(i, j))) + " ")
- Next j
- Label1.Text += vbNewLine
- Next i
- End Sub
- Private Function nCr(ByVal n As Integer, ByVal r As Integer) As Long
- If (n = r) Then
- nCr = 1
- Else
- nCr = Factorial(n) / (Factorial(n - r) * Factorial(r))
- End If
- End Function
- Private Function Factorial(ByVal n As Integer) As Long
- Dim i As Integer
- Factorial = 1
- If n <> 0 Then
- For i = 2 To n
- Factorial = Factorial * i
- Next i
- End If
- End Function
- Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
- Label1.Text = Nothing
- If Val(TextBox1.Text) > 20 Then
- Label1.Text = "(Number between 1 and 20)"
- ElseIf Val(TextBox1.Text) < 1 Then
- Label1.Text = "(Number between 1 and 20)"
- Else
- Command1_Click()
- End If
- End Sub
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement