By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,384 Members | 671 Online
Bytes IT Community
+ Ask a Question
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
Share this Question
Share on Google+
2 Replies


debasisdas
Expert 5K+
P: 8,127
Moved to Visual Basic Forum

MODERATOR.
Sep 10 '07 #2

QVeen72
Expert 100+
P: 1,445
Hi,

Keep one more Variable as sum_even
and change this Part :

Expand|Select|Wrap|Line Numbers
  1.  
  2. If x(i, j) Mod 2 = 1 Then
  3.   sum_odd = sum_odd + x(i, j)
  4. Else
  5.     sum_even = sum_even + x(i, j)
  6. End If
  7.  
Regards
Veena
Sep 10 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.