Problem 26. Determine if input is odd
Solution Stats
Problem Comments
-
48 Comments
Added several more tests to limit hard-coded answers.
When they say return "true" they mean "1", and "false" means "0". Newbie mistake.
Add a couple of negative values to the test.
Test for a couple of negative values
Delete comment doesn't work!
I don't know what I am doing wrong. I tried it in Matlab and seems to work fine
y = rem(x,2);
if y == 1
disp('true')
else
disp('false')
end
it should be clearly specified that we should not type in the string true but if we give true to a variable then it takes it as 1
All solutions with score 10 use the regexp cheat.
I don't understand why my code isn't working?
if mod(n,2) == 1
tf = 'true'
else
tf = 'false'
end
function tf = is_odd(n)
if rem(n,2)== 0
tf = 'false'
else
tf = 'true'
end
end
why is this not working?
I bet all the solutions not using if else are all from engineering backgrounds with intimate knowledge of boolean logic
ipek: you only need one end.
Nolan: you aren't using the variables provided
eine interessante Frage...
Persistent server error trying to evaluate this solution...
Hello it's me
Nice one
Good one.
Nice problem
nice
good job
horrible problem
good
great
good problem
Great problem
great prob
Easy one.
kool
Easy enough that I can do it!
badge
easy
how to reduce size
i have the size of 28
Good Problem
Pretty Easy. Thanks!
Good use of the modulo operator. Took some quick presence of mind to realise how to use it, but it is definitely quick to crack.
Advice: Don't overthink it!
Thank you!
Nice and simple. Thanks for the points :)
Thank you!
Adding comment for testing badges!!
Adding comment for testing badges!!
Solution stats show around 2/3rd of the attempts were wrong. Shows improtance of reading the problem well.
This is my first programming problem that I have written in c language.
Nice!
This was nice
Good Problem!
10/10 would code again
Not to hard
Solution Comments
Show commentsProblem Recent Solvers22239
Suggested Problems
-
4515 Solvers
-
4379 Solvers
-
11085 Solvers
-
419 Solvers
-
4516 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!