|
-
May 22nd, 2013, 03:57 PM
#11
Thread Starter
Junior Member
Re: Question Array + Function + GOD BLESS AMERICA
Hello! I want to add something to this code.
I want to add a inputbox which asks for number count.
For example if you enter 5, then you have 5 random numbers..
 Originally Posted by dunfiddlin
vb.net Code:
Option Strict On Public Class Form1 Dim r As New Random Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load Dim test(7) As Decimal ' set up a test array of For i = 0 To 7 test(i) = r.Next(11) ' random values 0 to 10 Next Me.Text = StandardDeviation(test).ToString ' function End Sub Function StandardDeviation(ByVal values() As Decimal) As Decimal Dim Mean As Decimal = values.Sum / values.Length ' get average of all array values Dim Diff As Decimal For Each d In values Diff = CDec(Diff + ((d - Mean) ^ 2)) ' calculate difference squares & sum them Next Return CDec(Math.Sqrt(Diff / values.Length)) ' return deviation End Function End Class
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|