Print all permutations of a number N greater than itself | C ++ implementation to print all the permutation greater than the integer N ; Function to print all the permutation which are greater than N itself ; Iterate and count the number of digits in N ; vector to print the permutations of N ; Store digits of N in the vector num ; Iterate over every permutation of N which is greater than N ; Print the current permutation of N ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void printPermutation ( int N ) { int temp = N , count = 0 ; while ( temp > 0 ) { count ++ ; temp /= 10 ; } vector < int > num ( count ) ; while ( N > 0 ) { num [ count -- - 1 ] = N % 10 ; N = N / 10 ; } while ( next_permutation ( num . begin ( ) , num . end ( ) ) ) { for ( int i = 0 ; i < num . size ( ) ; i ++ ) cout << num [ i ] ; cout << " STRNEWLINE " ; } } int main ( ) { int N = 324 ; printPermutation ( N ) ; return 0 ; }