Sum of array elements that is first continuously increasing then decreasing | Efficient C ++ method to find sum of the elements of array that is halfway increasing and then halfway decreassing ; Driver code
#include <iostream> NEW_LINE using namespace std ; int arraySum ( int arr [ ] , int n ) { int x = ( n + 1 ) / 2 ; return ( arr [ 0 ] - 1 ) * n + x * x ; } int main ( ) { int arr [ ] = { 10 , 11 , 12 , 13 , 12 , 11 , 10 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << arraySum ( arr , n ) ; return 0 ; }