如何确定一个数字是奇数还是偶数? [英] How to determine if a number is odd or even?

查看:247
本文介绍了如何确定一个数字是奇数还是偶数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想编写一些代码来确定在一个文本框txtnumber输入

的数字是奇数还是偶数。我该怎么做?


那么即使我想在这个数字上加3并乘以4

或者奇怪我想要加2来这个数字乘以5


感谢您的帮助。

解决方案

使用MOD功能:


dim Num为整数

如果cint(textbox1.text)MOD 2 = 0则

Num =( cint(textbox1.text)+ 3)* 4

else Num =(cint(textbox1.text)+ 2)* 5

endif

1月29日下午4:04,Ron < pts4 ... @ yahoo.comwrote:


您好,我想写一些代码来确定是否输入了一个数字

a textbox txtnumber是奇数或偶数。我该怎么做?


那么即使我想在这个数字上加3并乘以4

或者奇怪我想要加2来这个数字乘以5


感谢任何帮助。


是的,效果很好,


所以如果我想继续做一些事情,结果是1和将它添加到列表框中我会这样做吗?

......

num = txtnumber.text

而num<> 1

num =(1 + 0)/ 1

lsttresult.items.add(num)

''并且我想继续做以上操作并将其添加到lisbox

直到num = 1

我会怎么做?


1月29日下午5:11,ge0193 ... @ otc.edu写道:


使用MOD功能:


dim Num为整数

如果cint(textbox1.text)MOD 2 = 0则

Num =(cint( textbox1.text)+ 3)* 4

else Num =(cint(textbox1.text)+ 2)* 5

endif


1月29日下午4:04,Ron < pts4 ... @ yahoo.comwrote:


您好,我想写一些代码来确定是否输入了一个数字

a textbox txtnumber是奇数或偶数。我该怎么做呢?


然后,即使我想将3添加到该数字并乘以4

或者奇怪我想要添加2到那个数字并乘以5


感谢您的帮助.-隐藏引用的文字 - 显示引用的文字 -





1月29日下午5:35,Ron < pts4 ... @ yahoo.comwrote:


是的,效果很好,


所以如果我想保留做什么ubntil结果是1并且将它添加到列表框中我会这样做吗?

.....

num = txtnumber .text

而num<> 1

num =(1 + 0)/ 1

lsttresult.items。添加(num)

''并且我想继续做以上操作并将其添加到该lisbox

直到num = 1

这是我该怎么做?



哦,亲爱的,这让人感到困惑......你的循环条件表明循环

将作为只要num不等于1.然后你去下一行将num设置为

1.


Hello, I want to write some code to determine if a number entered in
a textbox txtnumber is odd or even. How do I do this?

Then if even I want to add 3 to that number and multiply by 4
Or if odd I want to add 2 to that number and multiply by 5

thanks for any help.

解决方案

Use the MOD function:

dim Num as integer
if cint(textbox1.text) MOD 2 = 0 then
Num = (cint(textbox1.text) + 3) * 4
else Num = (cint(textbox1.text) + 2) * 5
endif

On Jan 29, 4:04 pm, "Ron" <pts4...@yahoo.comwrote:

Hello, I want to write some code to determine if a number entered in
a textbox txtnumber is odd or even. How do I do this?

Then if even I want to add 3 to that number and multiply by 4
Or if odd I want to add 2 to that number and multiply by 5

thanks for any help.


yea that worked great,

so If I want to keep doing something ubntil the result is 1 and adding
it to a listbox would I do this?
......
num = txtnumber.text
while num <>1

num = (1 + 0 ) / 1
lsttresult.items.add (num)
'' AND I want to keep doing the above and adding it to that lisbox
until num = 1
Is that how I would do it?

On Jan 29, 5:11 pm, ge0193...@otc.edu wrote:

Use the MOD function:

dim Num as integer
if cint(textbox1.text) MOD 2 = 0 then
Num = (cint(textbox1.text) + 3) * 4
else Num = (cint(textbox1.text) + 2) * 5
endif

On Jan 29, 4:04 pm, "Ron" <pts4...@yahoo.comwrote:

Hello, I want to write some code to determine if a number entered in
a textbox txtnumber is odd or even. How do I do this?

Then if even I want to add 3 to that number and multiply by 4
Or if odd I want to add 2 to that number and multiply by 5

thanks for any help.- Hide quoted text -- Show quoted text -




On Jan 29, 5:35 pm, "Ron" <pts4...@yahoo.comwrote:

yea that worked great,

so If I want to keep doing something ubntil the result is 1 and adding
it to a listbox would I do this?
.....
num = txtnumber.text
while num <>1

num = (1 + 0 ) / 1
lsttresult.items.add (num)
'' AND I want to keep doing the above and adding it to that lisbox
until num = 1
Is that how I would do it?

Oh dear that''s confusing... your loop condition states that the loop
will run as long as num is not equal to 1. Then you go and set num to
1 on the very next line.


这篇关于如何确定一个数字是奇数还是偶数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆