Find bitwise AND ( & ) of all possible sub | C ++ program to find of all the sub - arrays ; function to return AND of sub - arrays ; Driver program ; size of the array ; print and of all subarrays
#include <bits/stdc++.h> NEW_LINE using namespace std ; int AND ( int a [ ] , int n ) { int ans = a [ 0 ] ; for ( int i = 0 ; i < n ; ++ i ) ans &= a [ i ] ; return ans ; } int main ( ) { int a [ ] = { 1 , 2 , 3 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; cout << AND ( a , n ) ; return 0 ; }