Binary array after M range toggle operations | CPP program to find modified array after m range toggle operations . ; function for toggle ; function for final processing of array ; function for printing result ; driver program ; function call for toggle ; process array ; print result
#include <bits/stdc++.h> NEW_LINE using namespace std ; void command ( bool arr [ ] , int a , int b ) { arr [ a ] ^= 1 ; arr [ b + 1 ] ^= 1 ; } void process ( bool arr [ ] , int n ) { for ( int k = 1 ; k <= n ; k ++ ) arr [ k ] ^= arr [ k - 1 ] ; } void result ( bool arr [ ] , int n ) { for ( int k = 1 ; k <= n ; k ++ ) cout << arr [ k ] << " ▁ " ; } int main ( ) { int n = 5 , m = 3 ; bool arr [ n + 2 ] = { 0 } ; command ( arr , 1 , 5 ) ; command ( arr , 2 , 5 ) ; command ( arr , 3 , 5 ) ; process ( arr , n ) ; result ( arr , n ) ; return 0 ; }