Decrement OR Increment
Practice this coding question on Coding Gurukul.
Problem statement
A warehouse uses a simple parity rule to move an inventory marker to a neighboring numbered slot. A marker in an even-numbered slot moves one slot backward, while a marker in an odd-numbered slot moves one slot forward. The operator needs a program that reports the destination after this single adjustment. Your task Given an integer N, output N - 1 if N is even, or N + 1 if N is odd. Perform exactly one adjustment. Important details There is only one number in the input, not a test-case count. Determine parity from the original number. Do not apply the rule again to the destination, since the machine makes only one move. Worked example A marker at slot 8 moves backward to slot 7 because 8 is even. A marker at slot 9 moves forward to slot 10 because 9 is odd.
Input format
One line contains the integer N.
Output format
Print the resulting integer.
Constraints
0 <= N <= 1000000000.
Sample input
8
Sample output
7
Sign in to run or submit a solution in C++, Java or Python.