Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class Form1
- Dim a(100) As Integer
- Dim n As Integer
- Private Sub Label2_Click(sender As Object, e As EventArgs) Handles lb_ds.Click
- End Sub
- ' tên của nút Thoát là cmdexit
- Private Sub cmdexit_Click(sender As Object, e As EventArgs) Handles cmdexit.Click
- If MessageBox.Show("Bạn có muốn thoát không?", "thông báo", MessageBoxButtons.YesNo) = (DialogResult.Yes) Then
- Application.Exit()
- End If
- End Sub
- ' tên nút Làm lại là cmdre
- Private Sub cmdre_Click(sender As Object, e As EventArgs) Handles cmdre.Click
- lb_ds.Text = ""
- lb_min.Text = ""
- txtk.Text = ""
- txtnhap.Text = ""
- txtnhap.Focus()
- cmdfind.Enabled = False
- cmdfindmin.Enabled = False
- End Sub
- ' tên nút Nhập số là cmdinput
- Private Sub cmdinput_Click(sender As Object, e As EventArgs) Handles cmdinput.Click
- Dim s, t As String
- If IsNumeric(txtnhap.Text) Then
- n = CInt(txtnhap.Text)
- For i = 0 To CInt(txtnhap.Text) - 1
- t = InputBox("Nhap so", "Thong bao ")
- a(i) = CInt(t)
- s = s + " " + t
- Next
- lb_ds.Text = "Dãy số vừa nhập là " + s
- cmdfind.Enabled = True
- cmdfindmin.Enabled = True
- End If
- End Sub
- 'tên nút Tìm số dương nhỏ nhất là cmdfindmin
- Private Sub cmdfindmin_Click(sender As Object, e As EventArgs) Handles cmdfindmin.Click
- Dim min As Integer
- min = 100000
- For i = 0 To n - 1
- If (a(i) > 0) Then
- min = Math.Min(min, a(i))
- End If
- Next
- lb_min.Text = "Số dương nhỏ nhất: " + CStr(min)
- End Sub
- 'tên nút Tìm là cmdfind
- Private Sub cmdfind_Click(sender As Object, e As EventArgs) Handles cmdfind.Click
- If IsNumeric(txtk.Text) Then
- Dim count As Integer
- For i = 0 To n - 1
- If (a(i) = CInt(txtk.Text)) Then
- count += 1
- End If
- Next
- Dim s As String
- s = "So phan tu co gia tri bang " + txtk.Text + " la " + CStr(count) + " phan tu tai vi tri :"
- For i = 0 To n - 1
- If (a(i) = CInt(txtk.Text)) Then
- s += CStr(i + 1) + ", "
- End If
- Next
- s = s.Remove(s.Length - 2)
- If (count <> 0) Then
- MessageBox.Show(s, "Thong bao", MessageBoxButtons.OK)
- End If
- End If
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement