TheAlgorithms/C++
1.0.0
All the algorithms implemented in C++
Toggle main menu visibility
Loading...
Searching...
No Matches
check_even_odd.cpp
Go to the documentation of this file.
1
33
34
#include <cassert>
35
#include <cstdint>
36
#include <iostream>
37
#include <string>
38
43
namespace
bit_manipulation
{
48
namespace
even_odd
{
49
55
bool
is_even
(std::int64_t N) {
56
return
(N & 1) == 0 ? true :
false
;
57
}
58
59
}
// namespace even_odd
60
}
// namespace bit_manipulation
61
66
static
void
test
() {
67
using
bit_manipulation::even_odd::is_even
;
68
69
// Test Even numbers
70
assert(is_even(0) ==
true
);
71
assert(is_even(2) ==
true
);
72
assert(is_even(100) ==
true
);
73
assert(is_even(-4) ==
true
);
74
assert(is_even(-1000) ==
true
);
75
76
// Test Odd numbers
77
assert(is_even(1) ==
false
);
78
assert(is_even(3) ==
false
);
79
assert(is_even(101) ==
false
);
80
assert(is_even(-5) ==
false
);
81
assert(is_even(-999) ==
false
);
82
83
std::cout <<
"All test cases successfully passed!"
<< std::endl;
84
}
85
90
int
main
() {
91
test
();
// run self-test implementations
92
return
0;
93
}
test
void test()
Definition
caesar_cipher.cpp:100
bit_manipulation::even_odd::is_even
bool is_even(std::int64_t N)
Checks if a number is even or odd using bitwise AND.
Definition
check_even_odd.cpp:55
main
int main()
Main function.
Definition
generate_parentheses.cpp:110
bit_manipulation
for std::string
even_odd
Functions for checking if a number is even or odd using bitwise operations.
bit_manipulation
check_even_odd.cpp
Generated by
1.18.0