早教吧 育儿知识 作业答案 考试题库 百科 知识分享

求高手帮我做个简单的VB程序Dividethenumberwith2.Converttheresulttoaninteger.Multiplythisintegerwith2.Iftheproductisequaltotheoriginalnumber,itisanevennumber,otherwiseitisanoddnumber.Toconvertanumbertoani

题目详情
求高手帮我做个简单的VB程序
Divide the number with 2.Convert the result to an integer.Multiply this integer with 2.If the product is equal to the original number,it is an even number,otherwise it is an odd number.
To convert a number to an integer you can use the function int(x) which returns the integer part of a value x.
▼优质解答
答案和解析
大体伪代码框架如下
y = int(x);
if(y/2*2 == y)
even()
else
odd()
另,这算法好傻,最快判断奇偶的话,只需要看整数的最后1位是0还是1就行了(因为计算机用的是二进制数)