Skip to main content

Write a VB Program to display all even and odd numbers from an array

· One min read
Kaustubh Kulkarni

file.vb
Private Sub cmdDisplay_Click()  
Dim a() As Integer
n = inputBox("How many elements do u want to enter")
ReDima(n)
Print "Array is : "
For i = 0 To n - 1
a(i) = Val(inputBox("Enter the Elements"))
Print a(i)
Next
Print "Even Numbers are: "
For i = 0 To n - 1
If a(i) Mod 2 = 0 Then
Print a(i)
End If
Next

Print "Odd Numbers are: "
For i = 0 To n - 1
If a(i) Mod 2 <> 0 Then
Print a(i)
End If
Next
End Sub