dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int LcmOfArray ( vector < int > arr , int idx ) { if ( idx == arr . size ( ) - 1 ) { return arr [ idx ] ; } int a = arr [ idx ] ; int b = LcmOfArray ( arr , idx + 1 ) ; return ( a * b / __gcd ( a , b ) ) ; } int main ( ) { vector < int > arr = { 1 , 2 , 8 , 3 } ; cout << LcmOfArray ( arr , 0 ) << " STRNEWLINE " ; arr = { 2 , 7 , 3 , 9 , 4 } ; cout << LcmOfArray ( arr , 0 ) << " STRNEWLINE " ; return 0 ; }

Index/key variables: idx
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isPower ( int x , long int y ) { if ( x == 1 ) return ( y == 1 ) ; long int pow = 1 ; while ( pow < y ) pow *= x ; return ( pow == y ) ; } int main ( ) { check the result for true / false and print cout << isPower ( 10 , 1 ) << endl ; cout << isPower ( 1 , 20 ) << endl ; cout << isPower ( 2 , 128 ) << endl ; cout << isPower ( 2 , 30 ) << endl ; return 0 ; }

Accumulator variables: pow, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countSquares ( int a , int b ) { return ( floor ( sqrt ( b ) ) - ceil ( sqrt ( a ) ) + 1 ) ; } int main ( ) { int a = 9 , b = 25 ; cout << " Count ▁ of ▁ squares ▁ is ▁ " << countSquares ( a , b ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findCountUpto ( int d ) { int GP1_Sum = 9 * ( ( pow ( 10 , d ) - 1 ) / 9 ) ; int GP2_Sum = 9 * ( ( pow ( 9 , d ) - 1 ) / 8 ) ; return GP1_Sum - GP2_Sum ; } int main ( ) { int d = 1 ; cout << findCountUpto ( d ) << endl ; d = 2 ; cout << findCountUpto ( d ) << endl ; d = 4 ; cout << findCountUpto ( d ) << endl ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void countDivisors ( int n ) { int count = 0 ; for ( int i = 1 ; i <= sqrt ( n ) + 1 ; i ++ ) { if ( n % i == 0 ) count += ( n / i == i ) ? 1 : 2 ; } if ( count % 2 == 0 ) cout << " Even " << endl ; else cout << " Odd " << endl ; } int main ( ) { cout << " The ▁ count ▁ of ▁ divisor : ▁ " ; countDivisors ( 10 ) ; return 0 ; }

Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int greyConverter ( int n ) { return n ^ ( n >> 1 ) ; } int main ( ) { int n = 3 ; cout << greyConverter ( n ) << endl ; n = 9 ; cout << greyConverter ( n ) << endl ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int largestPower ( int n , int p ) { int x = 0 ; while ( n ) { n /= p ; x += n ; } return x ; } int power ( int x , int y , int p ) { int res = 1 ; x = x % p ; while ( y > 0 ) { if ( y & 1 ) res = ( res * x ) % p ; x = ( x * x ) % p ; } return res ; } int modFact ( int n , int p ) { if ( n >= p ) return 0 ; int res = 1 ; bool isPrime [ n + 1 ] ; memset ( isPrime , 1 , sizeof ( isPrime ) ) ; for ( int i = 2 ; i * i <= n ; i ++ ) { if ( isPrime [ i ] ) { for ( int j = 2 * i ; j <= n ; j += i ) isPrime [ j ] = 0 ; } } for ( int i = 2 ; i <= n ; i ++ ) { if ( isPrime [ i ] ) { int k = largestPower ( n , i ) ; res = ( res * power ( i , k , p ) ) % p ; } } return res ; } int main ( ) { int n = 25 , p = 29 ; cout << modFact ( n , p ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, n, stdc, x
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int add ( int x , int y ) { while ( y > 0 && y -- ) x ++ ; while ( y < 0 && y ++ ) x -- ; return x ; } int main ( ) { cout << add ( 43 , 23 ) << endl ; cout << add ( 43 , -23 ) << endl ; return 0 ; }

Accumulator variables: stdc, x, y
C++ program:
#include <iostream>
using namespace std ; int countFact ( int low , int high ) { int fact = 1 , x = 1 ; while ( fact < low ) { fact = fact * x ; x ++ ; } int res = 0 ; while ( fact <= high ) { res ++ ; fact = fact * x ; x ++ ; } return res ; } int main ( ) { cout << " Count ▁ is ▁ " << countFact ( 2 , 720 ) ; return 0 ; }

Accumulator variables: res, x
C++ program:
#include <iostream>
using namespace std ; struct Date { int d , m , y ; } ; const int monthDays [ 12 ] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 } ; int countLeapYears ( Date d ) { int years = d . y ; if ( d . m <= 2 ) years -- ; return years / 4 - years / 100 + years / 400 ; } int getDifference ( Date dt1 , Date dt2 ) { long int n1 = dt1 . y * 365 + dt1 . d ; for ( int i = 0 ; i < dt1 . m - 1 ; i ++ ) n1 += monthDays [ i ] ; n1 += countLeapYears ( dt1 ) ; long int n2 = dt2 . y * 365 + dt2 . d ; for ( int i = 0 ; i < dt2 . m - 1 ; i ++ ) n2 += monthDays [ i ] ; n2 += countLeapYears ( dt2 ) ; return ( n2 - n1 ) ; } int main ( ) { Date dt1 = { 1 , 2 , 2000 } ; Date dt2 = { 1 , 2 , 2004 } ; cout << " Difference ▁ between ▁ two ▁ dates ▁ is ▁ " << getDifference ( dt1 , dt2 ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, n1, n2, years
Iterator variables: i
Class/struct names: Date
C++ program:
#include <iostream>
using namespace std ; int getPeriod ( int n ) { int rem = 1 ; for ( int i = 1 ; i <= n + 1 ; i ++ ) rem = ( 10 * rem ) % n ; int d = rem ; int count = 0 ; do { rem = ( 10 * rem ) % n ; count ++ ; } while ( rem != d ) ; return count ; } int main ( ) { cout << getPeriod ( 3 ) << endl ; cout << getPeriod ( 7 ) << endl ; return 0 ; }

Accumulator variables: count, i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int calculateAddedValue ( int number ) { int result = 0 ; int decimalPlace = 1 ; if ( number == 0 ) { result += ( 5 * decimalPlace ) ; } while ( number > 0 ) { if ( number % 10 == 0 ) { result += ( 5 * decimalPlace ) ; } number /= 10 ; decimalPlace *= 10 ; } return result ; } int replace0with5 ( int number ) { return number += calculateAddedValue ( number ) ; } int main ( ) { cout << replace0with5 ( 1020 ) ; }

Accumulator variables: decimalPlace, number, result, stdc
C++ program:
#include <iostream>
using namespace std ; double sum ( int n ) { double sum = 0 ; int fact = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { fact *= i ; sum += 1.0 / fact ; } return sum ; } int main ( ) { int n = 5 ; cout << sum ( n ) ; return 0 ; }

Accumulator variables: fact, i, sum
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; void print ( int n , int k ) { int rem = 1 ; for ( int i = 0 ; i < k ; i ++ ) { cout << ( 10 * rem ) / n ; rem = ( 10 * rem ) % n ; } } int main ( ) { int n = 7 , k = 3 ; print ( n , k ) ; cout << endl ; n = 21 , k = 4 ; print ( n , k ) ; return 0 ; }

Accumulator variables: i
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; class gfg { public : double sum ( int n ) { double i , s = 0.0 ; for ( i = 1 ; i <= n ; i ++ ) s = s + 1 / i ; return s ; } } ; int main ( ) { gfg g ; int n = 5 ; cout << " Sum ▁ is ▁ " << g . sum ( n ) ; return 0 ; }

Accumulator variables: i
Iterator variables: i
Class/struct names: gfg
C++ program:
#include <iostream>
using namespace std ; void rearrange ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) arr [ i ] += ( arr [ arr [ i ] ] % n ) * n ; for ( int i = 0 ; i < n ; i ++ ) arr [ i ] /= n ; } void printArr ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) cout << arr [ i ] << " ▁ " ; cout << endl ; } int main ( ) { int arr [ ] = { 3 , 2 , 0 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " Given ▁ array ▁ is ▁ STRNEWLINE " ; printArr ( arr , n ) ; rearrange ( arr , n ) ; cout << " Modified ▁ array ▁ is ▁ STRNEWLINE " ; printArr ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; void printArray ( int arr [ ] , int size ) { for ( int i = 0 ; i < size ; i ++ ) cout << " ▁ " << arr [ i ] ; cout << " STRNEWLINE " ; return ; } void printSequencesRecur ( int arr [ ] , int n , int k , int index ) { int i ; if ( k == 0 ) { printArray ( arr , index ) ; } if ( k > 0 ) { for ( i = 1 ; i <= n ; ++ i ) { arr [ index ] = i ; printSequencesRecur ( arr , n , k - 1 , index + 1 ) ; } } } void printSequences ( int n , int k ) { int * arr = new int [ k ] ; printSequencesRecur ( arr , n , k , 0 ) ; return ; } int main ( ) { int n = 3 ; int k = 2 ; printSequences ( n , k ) ; return 0 ; }

Index/key variables: i, index, k
Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void countPairs ( int arr [ ] , int N , int K ) { unordered_map < int , int > mp ; int cnt = 0 ; for ( int i = 0 ; i < N ; i ++ ) { cnt += mp [ K - arr [ i ] ] ; mp [ arr [ i ] ] ++ ; } cout << cnt ; } int main ( ) { int arr [ ] = { 1 , 5 , 4 , 8 , 7 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 9 ; countPairs ( arr , N , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: cnt, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int check ( int x ) { if ( ( ( x ) & ( x - 1 ) ) == 0 ) return 1 ; return 0 ; } int query ( int l , int r , int pre [ ] ) { if ( l == 0 ) return pre [ r ] ; else return pre [ r ] - pre [ l - 1 ] ; } void countInRange ( int arr [ ] , int N , vector < pair < int , int > > queries , int Q ) { int pre [ N ] = { 0 } ; pre [ 0 ] = check ( arr [ 0 ] ) ; for ( int i = 1 ; i < N ; i ++ ) { pre [ i ] = pre [ i - 1 ] + check ( arr [ i ] ) ; } int c = 0 ; while ( Q -- ) { int l = queries . first ; int r = queries . second ; c ++ ; cout << query ( l , r , pre ) << ' ▁ ' ; } } int main ( ) { int arr [ ] = { 12 , 11 , 16 , 8 , 2 , 5 , 1 , 3 , 256 , 1 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; vector < pair < int , int > > queries = { { 0 , 9 } , { 4 , 9 } } ; int Q = queries . size ( ) ; countInRange ( arr , N , queries , Q ) ; return 0 ; }

Index/key variables: N, i, r
Accumulator variables: Q, c, i, stdc
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int build_num ( int bit [ ] , int k ) { int ans = 0 ; for ( int i = 0 ; i < 32 ; i ++ ) if ( bit [ i ] == k ) ans += ( 1 << i ) ; return ans ; } int minimumAND ( int arr [ ] , int n , int k ) { int bit [ 32 ] = { 0 } ; for ( int i = 0 ; i < k ; i ++ ) { for ( int j = 0 ; j < 32 ; j ++ ) { if ( arr [ i ] & ( 1 << j ) ) bit [ j ] ++ ; } } int min_and = build_num ( bit , k ) ; for ( int i = k ; i < n ; i ++ ) { for ( int j = 0 ; j < 32 ; j ++ ) { if ( arr [ i - k ] & ( 1 << j ) ) bit [ j ] -- ; } for ( int j = 0 ; j < 32 ; j ++ ) { if ( arr [ i ] & ( 1 << j ) ) bit [ j ] ++ ; } min_and = min ( build_num ( bit , k ) , min_and ) ; } return min_and ; } int main ( ) { int arr [ ] = { 2 , 5 , 3 , 6 , 11 , 13 } ; int k = 3 ; int n = sizeof arr / sizeof arr [ 0 ] ; cout << minimumAND ( arr , n , k ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; typedef unsigned long long int ull ; ull calculate ( int bit_cnt ) { ull res = 1 ; while ( bit_cnt -- ) { res = res * 3 ; } return res ; } int unset_bit_count ( ull n ) { int count = 0 ; while ( n ) { if ( ( n & 1 ) == 0 ) count ++ ; n = n >> 1 ; } return count ; } int main ( ) { ull n ; n = 2 ; int count = unset_bit_count ( n ) ; ull ans = calculate ( count ) ; cout << ans << endl ; return 0 ; }

Accumulator variables: bit_cnt, count, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int solve ( int A [ ] , int B [ ] , int n ) { int cnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = i ; j < n ; j ++ ) if ( __builtin_popcount ( A [ i ] & A [ j ] ) == B [ j ] ) { cnt ++ ; } return cnt ; } int main ( ) { int A [ ] = { 2 , 3 , 1 , 4 , 5 } ; int B [ ] = { 2 , 2 , 1 , 4 , 2 } ; int size = sizeof ( A ) / sizeof ( A [ 0 ] ) ; cout << solve ( A , B , size ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: cnt, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void CalculatePairs ( int a [ ] , int n ) { int cnt_zero = 0 ; int cnt_one = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] % 2 == 0 ) cnt_zero += 1 ; else cnt_one += 1 ; } long int total_XOR_pairs = cnt_zero * cnt_one ; long int total_AND_pairs = ( cnt_one ) * ( cnt_one - 1 ) / 2 ; long int total_OR_pairs = cnt_zero * cnt_one + ( cnt_one ) * ( cnt_one - 1 ) / 2 ; cout << " cntXOR ▁ = ▁ " << total_XOR_pairs << endl ; cout << " cntAND ▁ = ▁ " << total_AND_pairs << endl ; cout << " cntOR ▁ = ▁ " << total_OR_pairs << endl ; } int main ( ) { int a [ ] = { 1 , 3 , 4 , 2 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; CalculatePairs ( a , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: cnt_one, cnt_zero, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void alternate ( int & a , int & b , int & x ) { x = a + b - x ; } int main ( ) { int a = -10 ; int b = 15 ; int x = a ; cout << " x ▁ is ▁ : ▁ " << x ; alternate ( a , b , x ) ; cout << " After change " cout << " STRNEWLINE x ▁ is ▁ : ▁ " << x ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void isSubsetAndZero ( int array [ ] , int length , int N ) { int arrAnd = array [ 0 ] ; for ( int i = 1 ; i < length ; i ++ ) { arrAnd = arrAnd & array [ i ] ; } if ( ( arrAnd & N ) == 0 ) cout << " YES " << endl ; else cout << " NO " << endl ; } int main ( ) { int array [ ] = { 1 , 2 , 4 } ; int length = sizeof ( array ) / sizeof ( int ) ; int N = 3 ; isSubsetAndZero ( array , length , N ) ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool findParity ( int x ) { int y = x ^ ( x >> 1 ) ; y = y ^ ( y >> 2 ) ; y = y ^ ( y >> 4 ) ; y = y ^ ( y >> 8 ) ; y = y ^ ( y >> 16 ) ; if ( y & 1 ) return 1 ; return 0 ; } int main ( ) { ( findParity ( 9 ) == 0 ) ? cout << " Even ▁ Parity STRNEWLINE " : cout << " Odd ▁ Parity STRNEWLINE " ; ( findParity ( 13 ) == 0 ) ? cout << " Even ▁ Parity STRNEWLINE " : cout << " Odd ▁ Parity STRNEWLINE " ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool allBitsSetInTheGivenRange ( unsigned int n , unsigned int l , unsigned int r ) { int num = ( ( 1 << r ) - 1 ) ^ ( ( 1 << ( l - 1 ) ) - 1 ) ; int new_num = n & num ; if ( num == new_num ) return true ; return false ; } bool bitsAreComplement ( unsigned int a , unsigned int b , unsigned int l , unsigned int r ) { unsigned int xor_value = a ^ b ; return allBitsSetInTheGivenRange ( xor_value , l , r ) ; } int main ( ) { unsigned int a = 10 , b = 5 ; unsigned int l = 1 , r = 3 ; if ( bitsAreComplement ( a , b , l , r ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int calculateSum ( int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum = sum + ( 1 << i ) ; } return sum ; } int main ( ) { int n = 10 ; cout << " Sum ▁ of ▁ series ▁ of ▁ power ▁ of ▁ 2 ▁ is ▁ : ▁ " << calculateSum ( n ) ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printCombinations ( int a [ ] , int n , int m ) { for ( int i = 0 ; i < ( 1 << n ) ; i ++ ) { int sum = 0 ; int num = 1 << ( n - 1 ) ; for ( int j = 0 ; j < n ; j ++ ) { if ( i & num ) sum += a [ j ] ; else sum += ( -1 * a [ j ] ) ; num = num >> 1 ; } if ( sum % m == 0 ) { num = 1 << ( n - 1 ) ; for ( int j = 0 ; j < n ; j ++ ) { if ( ( i & num ) ) cout << " + " << a [ j ] << " ▁ " ; else cout << " - " << a [ j ] << " ▁ " ; num = num >> 1 ; } cout << endl ; } } } int main ( ) { int a [ ] = { 3 , 5 , 6 , 8 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; int m = 5 ; printCombinations ( a , n , m ) ; return 0 ; }

Index/key variables: j
Accumulator variables: i, j, stdc, sum
Iterator variables: i, j
C++ program:
#include <iostream>
using namespace std ; int smallerNumsWithSameSetBits ( int n ) { int temp = __builtin_popcount ( n ) ; int count = 0 ; for ( int i = n - 1 ; i > 0 ; i -- ) { if ( temp == __builtin_popcount ( i ) ) count ++ ; } return count ; } int main ( ) { int n = 4 ; cout << smallerNumsWithSameSetBits ( n ) ; return 0 ; }

Accumulator variables: count, i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int multiplyWith4 ( int n ) { return ( n << 2 ) ; } int main ( ) { int n = 4 ; cout << multiplyWith4 ( n ) << endl ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define N  1000
int tree [ N ] ; int level [ N ] ; void constructTree ( int low , int high , int pos , int a [ ] ) { if ( low == high ) { level [ pos ] = 0 ; tree [ pos ] = a [ high ] ; return ; } int mid = ( low + high ) / 2 ; constructTree ( low , mid , 2 * pos + 1 , a ) ; constructTree ( mid + 1 , high , 2 * pos + 2 , a ) ; level [ pos ] = level [ 2 * pos + 1 ] + 1 ; if ( level [ pos ] & 1 ) tree [ pos ] = tree [ 2 * pos + 1 ] | tree [ 2 * pos + 2 ] ; else tree [ pos ] = tree [ 2 * pos + 1 ] ^ tree [ 2 * pos + 2 ] ; } void update ( int low , int high , int pos , int index , int a [ ] ) { if ( low == high and low == index ) { tree [ pos ] = a [ low ] ; return ; } if ( index < low index > high ) return ; if ( low != high ) { int mid = ( low + high ) / 2 ; update ( low , mid , 2 * pos + 1 , index , a ) ; update ( mid + 1 , high , 2 * pos + 2 , index , a ) ; if ( level [ pos ] & 1 ) tree [ pos ] = tree [ 2 * pos + 1 ] | tree [ 2 * pos + 2 ] ; else tree [ pos ] = tree [ 2 * pos + 1 ] ^ tree [ 2 * pos + 2 ] ; } } void updateValue ( int index , int value , int a [ ] , int n ) { a [ index ] = value ; update ( 0 , n - 1 , 0 , index , a ) ; } int main ( ) { int a [ ] = { 1 , 4 , 5 , 6 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; constructTree ( 0 , n - 1 , 0 , a ) ; int index = 0 ; int value = 2 ; updateValue ( index , value , a , n ) ; cout << tree [ 0 ] << endl ; index = 3 ; value = 5 ; updateValue ( index , value , a , n ) ; cout << tree [ 0 ] << endl ; return 0 ; }

Index/key variables: N, high, index, low, pos
Accumulator variables: stdc
C++ program:
#include <iostream>
using namespace std ; int evenbitsetnumber ( int n ) { int count = 0 , res = 0 ; for ( int temp = n ; temp > 0 ; temp >>= 1 ) { if ( count % 2 == 1 ) res |= ( 1 << count ) ; count ++ ; } return ( n res ) ; } / * Driver code * int main ( ) { int n = 10 ; cout << evenbitsetnumber ( n ) ; return 0 ; }

Accumulator variables: count, res
Iterator variables: temp
C++ program:
#include <iostream>
using namespace std ; int getmsb ( int n ) { n |= n >> 1 ; n |= n >> 2 ; n |= n >> 4 ; n |= n >> 8 ; n |= n >> 16 ; return ( n + 1 ) >> 1 ; } int getevenbits ( int n ) { n = getmsb ( n ) ; n |= n >> 2 ; n |= n >> 4 ; n |= n >> 8 ; n |= n >> 16 ; if ( n & 1 ) n = n >> 1 ; return n ; } int setallevenbits ( int n ) { return n | getevenbits ( n ) ; } int main ( ) { int n = 10 ; cout << setallevenbits ( n ) ; return 0 ; }

Accumulator variables: n
C++ program:
#include <iostream>
using namespace std ; int oddbitsetnumber ( int n ) { int count = 0 ; int res = 0 ; for ( int temp = n ; temp > 0 ; temp >>= 1 ) { if ( count % 2 == 0 ) res |= ( 1 << count ) ; count ++ ; } return ( n res ) ; } int main ( ) { int n = 10 ; cout << oddbitsetnumber ( n ) ; return 0 ; }

Accumulator variables: count, res
Iterator variables: temp
C++ program:
#include <iostream>
using namespace std ; int getmsb ( int n ) { n |= n >> 1 ; n |= n >> 2 ; n |= n >> 4 ; n |= n >> 8 ; n |= n >> 16 ; return ( n + 1 ) >> 1 ; } int getevenbits ( int n ) { n = getmsb ( n ) ; n |= n >> 2 ; n |= n >> 4 ; n |= n >> 8 ; n |= n >> 16 ; if ( ( n & 1 ) == 0 ) n = n >> 1 ; return n ; } int setalloddbits ( int n ) { return n | getevenbits ( n ) ; } int main ( ) { int n = 10 ; cout << setalloddbits ( n ) ; return 0 ; }

Accumulator variables: n
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printNumHavingAltBitPatrn ( int n ) { int curr_num = 1 ; cout << curr_num << " ▁ " ; while ( 1 ) { curr_num <<= 1 ; if ( n < curr_num ) break ; cout << curr_num << " ▁ " ; curr_num = ( ( curr_num ) << 1 ) ^ 1 ; if ( n < curr_num ) break ; cout << curr_num << " ▁ " ; } } int main ( ) { int n = 50 ; printNumHavingAltBitPatrn ( n ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; unsigned int perfectPowerOf2 ( unsigned int n ) { unsigned int per_pow = 1 ; while ( n > 0 ) { per_pow = per_pow << 1 ; n = n >> 1 ; } return per_pow ; } int main ( ) { unsigned int n = 128 ; cout << " Perfect ▁ power ▁ of ▁ 2 ▁ greater ▁ than ▁ " << n << " : ▁ " << perfectPowerOf2 ( n ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <stdio.h>
void findUniquePair ( int arr [ ] , int n ) { int XOR = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) XOR = XOR ^ arr [ i ] ; int set_bit_no = XOR & ~ ( XOR - 1 ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] & set_bit_no ) x = x ^ arr [ i ] ; else y = y ^ arr [ i ] ; } printf ( " The ▁ unique ▁ pair ▁ is ▁ ( % d , ▁ % d ) " , x , y ) ; } int main ( ) { int a [ ] = { 6 , 1 , 3 , 5 , 1 , 3 , 7 , 6 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; findUniquePair ( a , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; typedef unsigned int uint_t ; uint_t nxtHighWithNumOfSetBits ( uint_t x ) { uint_t rightOne ; uint_t nextHigherOneBit ; uint_t rightOnesPattern ; uint_t next = 0 ; if ( x ) { rightOne = x & - ( signed ) x ; nextHigherOneBit = x + rightOne ; rightOnesPattern = x ^ nextHigherOneBit ; rightOnesPattern = ( rightOnesPattern ) / rightOne ; rightOnesPattern >>= 2 ; next = nextHigherOneBit | rightOnesPattern ; } return next ; } int mthSmallestWithKSetBits ( uint_t m , uint_t k ) { uint_t num = ( 1 << k ) - 1 ; for ( int i = 1 ; i < m ; i ++ ) num = nxtHighWithNumOfSetBits ( num ) ; return num ; } int main ( ) { uint_t m = 6 , k = 4 ; cout << mthSmallestWithKSetBits ( m , k ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int countUnsetBits ( int n ) { int x = n ; n |= n >> 1 ; n |= n >> 2 ; n |= n >> 4 ; n |= n >> 8 ; n |= n >> 16 ; return __builtin_popcount ( x ^ n ) ; } int main ( ) { int n = 17 ; cout << countUnsetBits ( n ) ; return 0 ; }

Accumulator variables: n
C++ program:
#include <bits/stdc++.h>
using namespace std ; void toggle ( int & n ) { int temp = 1 ; while ( temp <= n ) { n = n ^ temp ; temp = temp << 1 ; } } int main ( ) { int n = 10 ; toggle ( n ) ; cout << n ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int isKthBitSet ( int x , int k ) { return ( x & ( 1 << ( k - 1 ) ) ) ? 1 : 0 ; } int leftmostSetBit ( int x ) { int count = 0 ; while ( x ) { count ++ ; x = x >> 1 ; } return count ; } int isBinPalindrome ( int x ) { int l = leftmostSetBit ( x ) ; int r = 1 ; while ( l > r ) { if ( isKthBitSet ( x , l ) != isKthBitSet ( x , r ) ) return 0 ; l -- ; r ++ ; } return 1 ; } int findNthPalindrome ( int n ) { int pal_count = 0 ; int i = 0 ; for ( i = 1 ; i <= INT_MAX ; i ++ ) { if ( isBinPalindrome ( i ) ) { pal_count ++ ; } if ( pal_count == n ) break ; } return i ; } int main ( ) { int n = 9 ; cout << findNthPalindrome ( n ) ; }

Accumulator variables: count, i, l, pal_count, r, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool LSB ( int num , int K ) { return ( num & ( 1 << ( K - 1 ) ) ) ; } int main ( ) { int num = 10 , K = 4 ; cout << LSB ( num , K ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void areSame ( int a , int b ) { if ( ! ( a - b ) ) cout << " Same " ; else cout << " Not ▁ Same " ; } int main ( ) { areSame ( 10 , 20 ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getRightMostSetBit ( int n ) { if ( n == 0 ) return 0 ; return log2 ( n & - n ) + 1 ; } int posOfRightMostDiffBit ( int m , int n ) { return getRightMostSetBit ( m ^ n ) ; } int main ( ) { int m = 52 , n = 24 ; cout << " Position ▁ of ▁ rightmost ▁ different ▁ bit : " << posOfRightMostDiffBit ( m , n ) << endl ; return 0 ; }

Accumulator variables: stdc