Write a function which returns 1 that 2 is passed and return 2 when 1 is passed.
A simple solution is to compare the passed value with 1 and 2.
Another solution is to use subtraction
We can also use bitwise xor operator.
This article is contributed by Anuj. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- Write your own atoi()
- Write your own strcmp that ignores cases
- Write an Efficient C Program to Reverse Bits of a Number
- Write an Efficient Method to Check if a Number is Multiple of 3
- Python map function | Count total set bits in all numbers from 1 to n
- Function to check if a singly linked list is palindrome
- Count of distinct XORs formed by rearranging two Binary strings
- XOR of all Prime numbers in an Array at positions divisible by K
- Find XOR of all elements in an Array
- Check if the XOR of an array of integers is Even or Odd
- Check if original Array is retained after performing XOR with M exactly K times
- Count number of binary strings without consecutive 1’s : Set 2
- Count of even and odd set bit with array element after XOR with K
- Count of even set bits between XOR of two arrays