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