Express a number as sum of consecutive numbers | Print consecutive numbers from last to first ; Driver Code
< ? php function printConsecutive ( $ last , $ first ) { echo $ first ++ ; for ( $ x = $ first ; $ x <= $ last ; $ x ++ ) echo " + " } function findConsecutive ( $ N ) { for ( $ last = 1 ; $ last < $ N ; $ last ++ ) { for ( $ first = 0 ; $ first < $ last ; $ first ++ ) { if ( 2 * $ N == ( $ last - $ first ) * ( $ last + $ first + 1 ) ) { echo $ N , " ▁ = ▁ " ; printConsecutive ( $ last , $ first + 1 ) ; return ; } } } echo " - 1" ; } $ n = 12 ; findConsecutive ( $ n ) ; ? >