You are on page 1of 2

Se citeste un sir de n termeni .

Sa se afiseze fiecare termen distinct al sirului urmat de numarul de


aparitii

(Varianta 6 bac)

Exemeplu

1 1 1 5 5 5 5 9 9 11 20 20 20 programul va afişa: 1 3 5 4 9 2 11 1 20 3 deoarece 1 apare de 3 ori, 5


apare de 4 ori, etc

Codul:
Public Class Form1
Dim n As Integer
Dim A(100) As Integer
Dim i As Integer
Dim j As Integer
Dim B(100) As Integer
Dim x As Integer
Dim y As Integer
Dim nr1 As Integer
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
n = nr.Text
x = InputBox("Numarul 1")
nr1 = 1
j = 1

For i = 1 To n - 1
y = InputBox("Numarul " + Str(i + 1))
If (x = y) Then
nr1 = nr1 + 1
Else
B(j) = x
B(j + 1) = nr1
j = j + 2
x = y
nr1 = 1

End If

If (x = y) Then
B(j) = x
B(j + 1) = nr1
End If
Next

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


For i = 1 To j + 1
trb2.AppendText(Str(B(i)) + " ")

trb2.AppendText(Environment.NewLine)

Next
End Sub
End Class

You might also like