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