MATLAB: Finding odd and even values without functions

evenhomeworkidentifyodd

Is it possible to identify if a value is even or odd using for loops instead of using a function (Ex. mod)? If possible, can someone show me?

Best Answer

What about dividing?
while 1
a = a/2;
if abs(a-1) < 0.01 % if very close to '1'
disp('even')
break;
elseif a < 1 % if smaller than '1'
disp('odd')
break;
end
end