奇数か否か

Hands Onの最初のVI:
単に奇数か否かを判定するだけのVIである。整数を2で割ってその余りが「0でないなら」(すなわち「偶数でないなら」、すなわち「奇数であるなら」) trueを出力する。整数しか受けつけないようにしてある。

I32のIはsigned Integer。
Rはremainder。
IQはinteger quotient。

isOdd.vi - Google ドライブ f:id:ti-nspire:20181103082332p:plain
 

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

f:id:ti-nspire:20181103083944p:plain:h200  
 

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

f:id:ti-nspire:20181103091811p:plain:h200
 

#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));
    }
}

f:id:ti-nspire:20181103104846p:plain:h200