429,384 Members | 671 Online
Need help? Post your question and get tips & solutions from a community of 429,384 IT Pros & Developers. It's quick & easy.

# Square of numbers in even rows in Visual Basic

 P: 1 How do I square the numbers in the even rows? I have generated 100 integer random numbers in the range of 1 to 100 in array x(10,10). Private Sub Form_Activate() Const row As Integer = 10 Const column As Integer = 10 Dim x(row, column) As Integer Dim i, j As Integer Dim low, high As Integer Dim sum As Integer Dim sum_odd As Integer low = 1 high = 100 Randomize For i = 1 To row For j = 1 To column x(i, j) = Int(low + (high - low + 1) * Rnd) Print Tab; x(i, j); ""; 'sum of all the odd numbers If x(i, j) Mod 2 = 1 Then sum_odd = sum_odd + x(i, j) End If Next j Print Next i sum = sum + x(1, 1) + x(2, 2) + x(3, 3) + x(4, 4) + x(5, 5) + x(6, 6) + x(7, 7) + x(8, 8) + x(9, 9) + x(10, 10) Print Print "Sum of diagonal elements=" & sum Print "Sum of all the odd numbers=" & sum_odd End Sub Please help! Sep 10 '07 #1