Zdravo svima.Imam problem sa resavanjem sledeceg zadatka:
Napisati programsku proceduru koja za dati celobrojni,nenegativni niz X ok k elemenata odredjuje aritmeticku sredinu svih razlicitih elemenata niza X
(na primer: X:3,5,3,6,4,6,3,4,3,4 k=10, aritmsredina=(3+5+6+4)/4=4,5)
Ja sam radio zadatak za izracunavanje aritmeticke sredine ali mi bas treba da izracunam artmeticku sredinu svih RAZLICITIH elemenata niza.
Imam jedan primer:
Public Class Form1
Private Sub Unesi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Unesi.Click
Dim i As Byte
Dim poruka As String
Dim naslov As String
n = Val(TextBox1.Text)
If n > 0 And n <= 100 Then
poruka = "Unesite sledeći element niza:"
For i = 1 To n
naslov = Str(i) & ".element niza"
X(i) = Val(InputBox(poruka, naslov))
Next i
Unesi.Visible = False
Sumiraj.Visible = True
Else
TextBox1.Text = ""
TextBox1.Focus()
End If
End Sub
Private Sub Sumiraj_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Sumiraj.Click
Dim s As Single
Dim a As Single
Dim i As Byte
s = 0
For i = 1 To n
s = s + X(i)
Next i
a = s / n
Label2.Text = "Suma niza je: " & Str(s)
Label3.Text = "Aritmetička sredina niza je: " & Str(a)
Sumiraj.Visible = False
End Sub
End Class
|