contoh 1 . menampilkan bilangan genap
cuplikan program
Public Class Form1
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim i As Integer
ListBox1.Items.Clear()
For i = 1 To Val(TextBox1.Text)
If i Mod 2 = 0 Then
ListBox1.Items.Add(i)
End If
Next
End Sub
End Class
Hasilnya
contoh 2 Menampilkan bilangan 4,7,8,14,16,28,32,56...
Listing programnya:
Public Class Form2
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim i, u, y As Integer
u = 4
y = 7
For i = 1 To Val(TextBox1.Text)
If i Mod u = 0 Then
ListBox1.Items.Add(i)
u = i
Else
If i Mod y = 0 Then
ListBox1.Items.Add(i)
y = i
End If
End If
Next
End Sub
End Class
Hasil:
Tidak ada komentar:
Posting Komentar