Equal Sum and XOR | C ++ program to print count of values such that n + i = n ^ i ; function to count number of values less than equal to n that satisfy the given condition ; Traverse all numbers from 0 to n and increment result only when given condition is satisfied . ; Driver program
#include <iostream> NEW_LINE using namespace std ; int countValues ( int n ) { int countV = 0 ; for ( int i = 0 ; i <= n ; i ++ ) if ( ( n + i ) == ( n ^ i ) ) countV ++ ; return countV ; } int main ( ) { int n = 12 ; cout << countValues ( n ) ; return 0 ; }