Find the largest number that can be formed with the given digits | C ++ program to generate largest possible number with given digits ; Function to generate largest possible number with given digits ; sort the given array in descending order ; generate the number ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findMaxNum ( int arr [ ] , int n ) { sort ( arr , arr + n , greater < int > ( ) ) ; int num = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { num = num * 10 + arr [ i ] ; } return num ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 0 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findMaxNum ( arr , n ) ; return 0 ; }