vb怎么用if then编写区分偶数奇数的? 判断奇偶数的vb程序段

VB\u600e\u4e48\u7528\u5206\u652f\u7ed3\u6784\uff08if\u3002\u3002then\u3002\u3002else\uff09\u5224\u65ad\u5947\u6570\u548c\u5076\u6570

if (intNum mod 2=0) thenmgsbox "\u8fd9\u4e2a\u6570\u662f\u5076\u6570\u201celsemgsbox "\u8fd9\u4e2a\u6570\u662f\u5947\u6570\u201cendif

vb\u7a0b\u5e8f\u6bb5\u5982\u4e0b\uff1a
Private Sub Command1_Clicko
If Val\uff08Text1.Text\uff09Mod 2 = 1 And Val\uff08Text1.Text\uff09= Int\uff08Val\uff08Text1.Text\uff09Then
Label1.Caption="\u8fd9\u662f\u5947\u6570"
Else
If Val\uff08Text1.Text\uff09Mod 2= 0 And Val\uff08Text1.Text\uff09= Int\uff08Val\uff08Text1.Text\uff09\uff09Then
Label1.Caption ="\u8fd9\u662f\u5076\u6570"
Else
Label1.Caption ="\u975e\u5947\u975e\u5076"
End If
End If
End Sub

\u6269\u5c55\u8d44\u6599\uff1a
\u5224\u65ad\u5947\u5076\u6570\u65f6\uff0c\u4e3b\u8981\u662f\u4f7f\u7528\u8fd0\u7b97\u7b26-Mod\u548cif\u8bed\u53e5\uff0cMod\u53ef\u4ee5\u5bf9\u4e00\u4e2a\u6570\u53d6\u4f59\u6570\u3002\u4f8b\u598210/3= 3....11\u521910 Mod 3=1\uff0c\u6240\u4ee5\u5982\u679c\u4efb\u610f\u4e00\u4e2a\u6570n Mod 2=1\u8fd9\u4e2a\u6570\u5c31\u662f\u5947\u6570\u3002
If\u8bed\u53e5\u683c\u5f0f\uff1a\u5982\u679c\u6761\u4ef61\u6210\u7acb \u505a\u4ee3\u78011 \u5426\u5219 \u505a\u4ee3\u78012 \u7ed3\u675f
\u4ee3\u7801\u683c\u5f0f\uff1a
IfA1 Then
\u8bed\u53e51
Else
\u8bed\u53e52
End if

首先看是不是正整数,然后再判断能不能被2整除就行了。
if n=int(n) and n>=0 and n mod 2=0 then
偶数
else
奇数
endif

下面都是你要的答案楼上说得很对
1。
if n mod 2=0 then
n是偶数
else
n是奇数
end if
2。
if n=int(n) and n>=0 and n mod 2=0 then
偶数
else
奇数
end if
3。
if i\2 =i/2 then debug.print i & "是偶数"
else
debug.print i & "是奇数"
end if

if x mod 2 =0 then
x是偶数
else
x是奇数
end if

如果我们的要判断的数定义为n
那么
if n mod 2=0 then
n是偶数
else
n是奇数
end if

if i mod 2=0 then
print "偶数"
else
print"奇数"

if i\2 =i/2 then
debug.print i & "是偶数"
else
debug.print i & "是奇数"
end if

扩展阅读:爱心代码编程可复制 ... vba if then ... vb if then语句用法 ... 使用if-then规则求解问题 ... vba else if语句怎么用 ... if then语句使用教程 ... 宏程序if then编程的格式 ... 西门子if then语句用法 ... vb字体大小调整代码 ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网