473,386 Members | 1,754 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

even numbers

how can i check if a variable is an even number?
Jul 22 '05 #1
4 1753

"polilop" <fm******@inet.hr> wrote in message
news:el**************@TK2MSFTNGP09.phx.gbl...
how can i check if a variable is an even number?


Assuming the variable identifier is 'n':

If (n Mod 2) = 0 Then ...

Mod is the VBS modulus operator, it returns the remainder of a division
operation.
-Mark
Jul 22 '05 #2
did not know that,
thank you.
"Mark J. McGinty" <mm******@spamfromyou.com> wrote in message
news:eI**************@TK2MSFTNGP12.phx.gbl...

"polilop" <fm******@inet.hr> wrote in message
news:el**************@TK2MSFTNGP09.phx.gbl...
how can i check if a variable is an even number?


Assuming the variable identifier is 'n':

If (n Mod 2) = 0 Then ...

Mod is the VBS modulus operator, it returns the remainder of a division
operation.
-Mark

Jul 22 '05 #3
Mark J. McGinty wrote:
If (n Mod 2) = 0 Then ...


Alternatively:
If n/2 = n\2 Then ...

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Jul 22 '05 #4

"Dave Anderson" <GT**********@spammotel.com> wrote in message
news:ew**************@TK2MSFTNGP09.phx.gbl...
Mark J. McGinty wrote:
If (n Mod 2) = 0 Then ...
Alternatively:
If n/2 = n\2 Then ...


But that incurs overhead for an integer division op, plus a floating point
division op, then a comparison of floats (after implicit type promotion of
the integer expression.)

Mod is just one integer division op, (unless n happens to be floating point)
and then integer comparison. Further, Mod will tolerate Empty as the first
operand.

Lastly... well "intuitive" is in the eye of the beholder, so I'll skip the
rest.
-Mark

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message.
Use of this email address implies consent to these terms. Please do not
contact me directly or ask me to contact you directly for assistance. If
your question is worth asking, it's worth posting.

Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Debbie Lucier | last post by:
How would I generate a even random number each time? I can generate a random number each time but not an even one? Here is the code I use for the random number from 1-100. <script...
2
by: Lance Hoffmeyer | last post by:
So, I have using the following to grab numbers from MS Word. I discovered that that there is a "special" rule being used for rounding. If a ??.5 is even the number is to rounded down (20.5 = 20)...
1
sonic
by: sonic | last post by:
During input validation, how would one decipher between even and odd numbers? I have to write a program that allows an individual to select numbers between 2-14, excluding odds. Here is a snippet...
17
by: Ron | last post by:
I want to write a program that will accept a number in a textbox for example 23578 and then in a label will display the sum of the odd and even number like this... the textbox containsthe number...
6
by: devoreband | last post by:
hey i wrote all my code but i need to print out only the even numbers so is there any predefined function i can use or what can structure i should be following? ........ 16 for(int r = 0;...
2
by: cmeekeen | last post by:
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...
25
by: melsayid | last post by:
The program always shows that the input is odd. int main () { int n, d; printf ("Enter a Number: "); scanf ("%d", &n); d=1; if (d==n)
30
by: bdsatish | last post by:
The built-in function round( ) will always "round up", that is 1.5 is rounded to 2.0 and 2.5 is rounded to 3.0. If I want to round to the nearest even, that is my_round(1.5) = 2 # As...
18
by: =?ISO-8859-1?Q?Ney_Andr=E9_de_Mello_Zunino?= | last post by:
Hello. It seems a year is all it takes for one's proficiency in C++ to become too rusty. Professionally, I've been away from the language (and from programming in general), but I still preserve...
2
by: colordrm88 | last post by:
Here is what I am supposed to do...Write a C++ program that asks for 10 numbers and prints the sum of only the even numbers. I also have to use an if statement and a while loop. Please please...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...

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.