- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# C++ program to find maximum possible value for which XORed sum is maximum

Suppose we have two numbers a and b. We have to find the smallest possible value of (a XOR x) + (b XOR x) for some value of x.

So, if the input is like a = 6; b = 12, then the output will be 10, because if x = 4, then (6 XOR 4) + (12 XOR 4) = 2 + 8 = 10.

## Steps

To solve this, we will follow these steps −

return a XOR b

## Example

Let us see the following implementation to get better understanding −

#include<bits/stdc++.h> using namespace std; int solve(int a, int b){ return (a^b); } int main(){ int a = 6; int b = 12; cout << solve(a, b) << endl; }

## Input

6, 12

## Output

10

- Related Articles
- C++ program to find maximum possible value of XORed sum
- C++ program to find maximum possible median of elements whose sum is s
- Program to find maximum possible value of smallest group in Python
- Find maximum sum possible equal sum of three stacks in C++
- Find maximum possible stolen value from houses in C++
- Program to find minimum possible maximum value after k operations in python
- Program to find maximum adjacent absolute value sum after single reversal in C++
- Program to find maximum weighted sum for rotated array in Python
- C++ program to find out the maximum possible tally from given integers
- Program to find sum of k non-overlapping sublists whose sum is maximum in C++
- C++ Program to Find Maximum Value of any Algebraic Expression
- C++ program to find out the maximum value of i
- What is the maximum possible value of an integer in C# ?
- Find the maximum possible value of the minimum value of modified array in C++
- C++ program to find maximum possible amount of allowance after playing the game

Advertisements