Print prime factors of a given integer in decreasing order using Stack | Function to print prime factors of N in decreasing order ; Stores prime factors of N in decreasing order ; Insert i into stack ; Update N ; Update i ; Print value of stack st ; Driver Code ; Function Call
function PrimeFactors ( N ) { let st = [ ] ; let i = 2 ; while ( N != 1 ) { if ( N % i == 0 ) { st . push ( i ) ; while ( N % i == 0 ) { N = Math . floor ( N / i ) ; } } i ++ ; } while ( st . length != 0 ) { document . write ( st . pop ( ) ) ; } } let N = 8 ; PrimeFactors ( N ) ;