Print prime factors of a given integer in decreasing order using Stack | C # program for the above approach ; 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
using System ; using System . Collections . Generic ; class GFG { static void PrimeFactors ( int N ) { Stack < int > st = new Stack < int > ( ) ; int i = 2 ; while ( N != 1 ) { if ( N % i == 0 ) { st . Push ( i ) ; while ( N % i == 0 ) { N = N / i ; } } i ++ ; } while ( st . Count != 0 ) { Console . Write ( st . Peek ( ) ) ; st . Pop ( ) ; } } public static void Main ( ) { int N = 8 ; PrimeFactors ( N ) ; ; } }