Check if an array is increasing or decreasing | C ++ implementation of the approach ; Function to check the type of the array ; If the first two and the last two elements of the array are in increasing order ; If the first two and the last two elements of the array are in decreasing order ; If the first two elements of the array are in increasing order and the last two elements of the array are in decreasing order ; If the first two elements of the array are in decreasing order and the last two elements of the array are in increasing order ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void checkType ( int arr [ ] , int n ) { if ( arr [ 0 ] <= arr [ 1 ] && arr [ n - 2 ] <= arr [ n - 1 ] ) cout << " Increasing " ; else if ( arr [ 0 ] >= arr [ 1 ] && arr [ n - 2 ] >= arr [ n - 1 ] ) cout << " Decreasing " ; else if ( arr [ 0 ] <= arr [ 1 ] && arr [ n - 2 ] >= arr [ n - 1 ] ) cout << " Increasing ▁ then ▁ decreasing " ; else cout << " Decreasing ▁ then ▁ increasing " ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; checkType ( arr , n ) ; return 0 ; }