Determine the parity of data in matlab (mod function, rem function)

Use Matlab to determine whether a number is even or odd

1. mod function

X = 25;%要判断的数
if mod(X,2)==1
    disp('奇数');%奇数
else
    disp('偶数');%偶数
end

result
Insert image description here

2. rem function

n=25;
if rem(n,2)==0
    display('偶数');
else
    display('奇数');
end

result
Insert image description here

Guess you like

Origin blog.csdn.net/iii66yy/article/details/132443553