Check if all elements of a Circular Array can be made equal by increments of adjacent pairs | C ++ Program to implement the above approach ; Function to check if all array elements can be made equal ; Stores the sum of even and odd array elements ; If index is odd ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool checkEquall ( int arr [ ] , int N ) { int sumEven = 0 , sumOdd = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( i & 1 ) sumOdd += arr [ i ] ; else sumEven += arr [ i ] ; } if ( sumEven == sumOdd ) return true ; else return false ; } int main ( ) { int arr [ ] = { 2 , 7 , 3 , 5 , 7 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; if ( checkEquall ( arr , N ) ) cout << " YES " << endl ; else cout << " NO " << endl ; return 0 ; }