Modify a binary array to Bitwise AND of all elements as 1 | C ++ implementation of the above approach ; Function to check if it is possible or not ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool check ( int a [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) if ( a [ i ] ) return true ; return false ; } int main ( ) { int a [ ] = { 0 , 1 , 0 , 1 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; check ( a , n ) ? cout << " YES STRNEWLINE " : cout << " NO STRNEWLINE " ; return 0 ; }