Print all the permutation of length L using the elements of an array | Iterative | C # implementation for above approach ; Convert the number to Lth base and print the sequence ; Sequence is of length L ; Print the ith element of sequence ; Print all the permuataions ; There can be ( len ) ^ l permutations ; Convert i to len th base ; Driver code ; function call
using System ; class GFG { static void convert_To_Len_th_base ( int n , int [ ] arr , int len , int L ) { for ( int i = 0 ; i < L ; i ++ ) { Console . Write ( arr [ n % len ] ) ; n /= len ; } Console . WriteLine ( ) ; } static void print ( int [ ] arr , int len , int L ) { for ( int i = 0 ; i < ( int ) Math . Pow ( len , L ) ; i ++ ) { convert_To_Len_th_base ( i , arr , len , L ) ; } } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 } ; int len = arr . Length ; int L = 2 ; print ( arr , len , L ) ; } }