Hands Onの最初のVI:
単に奇数か否かを判定するだけのVIである。整数を2で割ってその余りが「0でないなら」(すなわち「偶数でないなら」、すなわち「奇数であるなら」) trueを出力する。整数しか受けつけないようにしてある。
I32のIはsigned Integer。
Rはremainder。
IQはinteger quotient。
def isOdd(Int): Int = round(Int) return Int, Int % 2 != 0 i = -5 while(i<5): print("%0.1f is odd? %s" % (i, isOdd(i))) i += 0.4
function isOdd(Int) local Int = math.floor(Int + 0.5) return Int, Int % 2 ~= 0 end for i = -5, 5, 0.4 do print(string.format("%.1f is odd? (%s, %s)", i, isOdd(i))) end
#include "mbed.h" int isOdd(int Int){ return Int % 2 != 0; } int main(){ for(int i=-5; i<5; i++){ printf("%d is odd? %d\n", i, isOdd(i)); } }