Write a C/C++ program that accepts a number from the user and prints “Even” if the entered number is even and prints “Odd” if the number is odd. You are not allowed to use any comparison (==, <,>,…etc) or conditional (if, else, switch, ternary operator,..etc) statement.
Below is a tricky code can be used to print “Even” or “Odd” accordingly.
Below is another tricky code can be used to print “Even” or “Odd” accordingly. Thanks to student for suggesting this method.
Please write comments if you find the above code incorrect, or find better ways to solve the same problem
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Implementing ternary operator without any conditional statement
- Conditional or Ternary Operator (?:) in C/C++
- Set a variable without using Arithmetic, Relational or Conditional Operator
- Conditionally assign a value without using conditional and arithmetic operators
- Switch Statement in C/C++
- Break Statement in C/C++
- Continue Statement in C/C++
- goto statement in C/C++
- C/C++ if statement with Examples
- C/C++ if else statement with Examples
- Nested switch statement in C++
- return statement in C/C++ with Examples
- Interesting facts about switch statement in C
- return statement vs exit() in main()
- Programming puzzle (Assign value without any control statement)
- Data type of case labels of switch statement in C++?
- How to print % using printf()?
- How to print a variable name in C?
- How will you print numbers from 1 to 100 without using loop? | Set-2
- Print 1 2 3 infinitely using threads in C