[HELP] Finding the averages on a 2D array (Diagonally)[Solved]
So i was able to figure out the average of each row and column, now i want to find the average diagonally.
Here is what i have so far.
[php] Private Sub arrayavg()
'6 by 6 (2D) array with random number in the range 1 to 10.
'Then determine the average of each row and each column.
'In addition, determine the average of each diagonal.
lstout.Items.Clear()
Dim square(6, 6) As Integer
Dim row, col As Integer
Dim rndnum As New Random 'Generates Random Numbers, I have it set 1-10
Dim sum As Integer = 0
Dim ave As Double = 0
Dim sum1 As Integer = 0
Dim sum2 As Integer = 0
For row = 1 To 6
sum = 0
For col = 1 To 6
square(row, col) = rndnum.Next(1, 10)
sum = sum + square(row, col)
Next
ave = sum / 6.0
lstout.Items.Add("ave for row " & row & " = " & Math****und(ave, 2))
Next
lstout.Items.Add(ControlChars.NewLine)
For col = 1 To 6
sum = 0
For row = 1 To 6
sum = sum + square(row, col)
Next
ave = sum / 6.0
lstout.Items.Add("ave for col " & col & " = " & Math****und(ave, 2))
Next
lstout.Items.Add(ControlChars.NewLine)
End Sub[/php]
I am absolutely clueless on how to get the average for the diagonal, help?
Note: the line :
[php]lstout.Items.Add("ave for col " & col & " = " & Math****und(ave, 2))[/php]
MATH****UND is MATH . ROUND.
Here is what i have so far.
[php] Private Sub arrayavg()
'6 by 6 (2D) array with random number in the range 1 to 10.
'Then determine the average of each row and each column.
'In addition, determine the average of each diagonal.
lstout.Items.Clear()
Dim square(6, 6) As Integer
Dim row, col As Integer
Dim rndnum As New Random 'Generates Random Numbers, I have it set 1-10
Dim sum As Integer = 0
Dim ave As Double = 0
Dim sum1 As Integer = 0
Dim sum2 As Integer = 0
For row = 1 To 6
sum = 0
For col = 1 To 6
square(row, col) = rndnum.Next(1, 10)
sum = sum + square(row, col)
Next
ave = sum / 6.0
lstout.Items.Add("ave for row " & row & " = " & Math****und(ave, 2))
Next
lstout.Items.Add(ControlChars.NewLine)
For col = 1 To 6
sum = 0
For row = 1 To 6
sum = sum + square(row, col)
Next
ave = sum / 6.0
lstout.Items.Add("ave for col " & col & " = " & Math****und(ave, 2))
Next
lstout.Items.Add(ControlChars.NewLine)
End Sub[/php]
I am absolutely clueless on how to get the average for the diagonal, help?
Note: the line :
[php]lstout.Items.Add("ave for col " & col & " = " & Math****und(ave, 2))[/php]
MATH****UND is MATH . ROUND.
