Question #58973

Write a vb 6 programs that takes n numbers as input it prints the maximum numbers and it's frequency(number of occurence )
1

Expert's answer

2016-04-12T15:11:05-0400

VERSION 5.00

Begin VB.Form Form1

Caption = "Frequency"

ClientHeight = 5700

ClientLeft = 120

ClientTop = 465

ClientWidth = 4155

LinkTopic = "Form1"

ScaleHeight = 5700

ScaleWidth = 4155

StartUpPosition = 3 'Windows Default

Begin VB.TextBox Text2

Height = 2295

Left = 600

MultiLine = -1 'True

ScrollBars = 2 'Vertical

TabIndex = 3

Top = 2760

Visible = 0 'False

Width = 2895

End

Begin VB.CommandButton Command1

Caption = "Run"

Height = 495

Left = 1080

TabIndex = 1

Top = 960

Width = 1695

End

Begin VB.TextBox Text1

Height = 375

Left = 480

TabIndex = 0

Text = "2 3 5 88 9 2 3"

Top = 360

Width = 3255

End

Begin VB.Label Label1

Enabled = 0 'False

Height = 375

Left = 1080

TabIndex = 2

Top = 2280

Width = 2055

End

End

Attribute VB_Name = "Form1"

Attribute VB_GlobalNameSpace = False

Attribute VB_Creatable = False

Attribute VB_PredeclaredId = True

Attribute VB_Exposed = False

' Question #58973, Programming & Computer Science / Visual Basic


Private Sub Command1_Click()
    Dim frequency() As Integer
    Dim arr() As Integer
    Dim arrS() As String
    arrS = Split(Text1, " ")
    n = UBound(arrS)
    ReDim arr(n)
    Dim i As Integer
    Dim max As Integer
    max = Val(arrS(0))
    k = 0
    For i = 0 To UBound(arrS)
        If Len(Trim(arrS(i))) > 0 Then
            arr(k) = Val(arrS(i))
            If max < arr(k) Then max = arr(k)
            k = k + 1
        End If
    Next i
    ReDim frequency(max)
    For i = 0 To k - 1
        frequency(arr(i)) = frequency(arr(i)) + 1
    Next i
    res = ""
    For i = 0 To max
        If frequency(i) > 0 Then res = res & i & " - frequency " & frequency(i) & vbNewLine
    Next i
    Label1 = "Maximum" & max
    Text2 = res
    Text2.Visible = True
End Sub

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS