473,508 Members | 4,779 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Square of numbers in even rows in Visual Basic

1 New Member
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
2 2405
debasisdas
8,127 Recognized Expert Expert
Moved to Visual Basic Forum

MODERATOR.
Sep 10 '07 #2
QVeen72
1,445 Recognized Expert Top Contributor
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

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

Similar topics

7
6061
by: Ariel | last post by:
I have a question that I'm hoping someone here can answer. Let's say I have two fields which have a beginning number and an ending number. What I'd like to do is have Access generate a list of...
3
4856
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
8
58639
by: moondaddy | last post by:
I need to loop through an array and determine which indexes are odd and which are even. how can I determine if a number is an odd number or an even number? -- moondaddy@nospam.com
3
24506
by: JoelPJustice | last post by:
I am working through a VBA book by myself to help and try and improve my skills. However, the book does not give you solutions to certain problems. I have worked through this problem up until bullet...
4
8442
by: sathyashrayan | last post by:
(This is not a home work question) Dear group, I want a program to find one number between a set of natural number.A program to guess a number in between a Natural number set.This should be a...
6
19650
by: Bill Nguyen | last post by:
I tried almost everything ..Rows.clear() ..rowcount = 0 and the rows in a datagridview still not cleared I populated the Datagridview manually using Row.Add Any help is greatly appreciated ...
3
6623
by: Brad Foster | last post by:
on my assignment I need to ask a user for two numbers output all the odd # between the two # output the sum of the even # *output the # and squares between 1-10* *output the sum of the square...
4
3398
by: inferi9 | last post by:
Hi, I am working in a program caals magic square and it must be done only with loops and user definied funcations,I will tell you about my code and where my problem, the main is only calls the other...
3
5555
by: Sejoro | last post by:
Hey again, I'm trying to write a program that will output a random valid Latin Square (9x9 square of numbers 1 - 9 with no repetition in the rows and columns) and can't get my numbers to not...
0
7228
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7332
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7393
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5635
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4715
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
426
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.