TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
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
43namespace bit_manipulation {
48namespace 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
66static void test() {
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
90int main() {
91 test(); // run self-test implementations
92 return 0;
93}
static void test()
Self-test implementations.
bool is_even(std::int64_t N)
Checks if a number is even or odd using bitwise AND.
int main()
Main function.
for std::string
Functions for checking if a number is even or odd using bitwise operations.