Find the slope of the given number | function to find slope of a number ; to store slope of the given number ' num ' ; loop from the 2 nd digit up to the 2 nd last digit of the given number ' num ' ; if the digit is a maxima ; if the digit is a minima ; required slope ; Driver Code
< ? php function slopeOfNum ( $ num , $ n ) { $ slope = 0 ; for ( $ i = 1 ; $ i < $ n - 1 ; $ i ++ ) { if ( $ num [ $ i ] > $ num [ $ i - 1 ] && $ num [ $ i ] > $ num [ $ i + 1 ] ) $ slope ++ ; else if ( $ num [ $ i ] < $ num [ $ i - 1 ] && $ num [ $ i ] < $ num [ $ i + 1 ] ) $ slope ++ ; } return $ slope ; } $ num = "1213321" ; $ n = strlen ( $ num ) ; echo " Slope = " ? >