isodd
isodd(x::Integer) -> Bool
Returns true
if x
is odd (that is, not divisible by 2), and false
otherwise.
julia> isodd(9)
true
julia> isodd(10)
false
Examples
Check if a number is odd:
In Julia, you can use the isodd
function to determine whether a given integer is odd or not. It returns true
if the number is odd and false
otherwise.
julia> isodd(9)
true
julia> isodd(10)
false
Here are a few common examples of using the isodd
function:
-
Check if a variable is an odd number:
julia> num = 7; julia> isodd(num) true
-
Use
isodd
in conditional statements:julia> x = 12; julia> if isodd(x) println("The number is odd.") else println("The number is even.") end
- Filter odd numbers from an array:
julia> numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; julia> filter(isodd, numbers) 5-element Array{Int64,1}: 1 3 5 7 9
Remember, the isodd
function is applicable only to integers (Int
type) and not to other numeric types.
See Also
digits, inf, isdigit, iseven, isfinite, isless, islower, isnumber, isodd, isprime, isqrt, issorted, issubnormal, isxdigit, nan,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.