Maximum number by concatenating every element in a rotation of an array | C ++ program to print the Maximum number by concatenating every element in rotation of array ; Function to print the largest number ; store the index of largest left most digit of elements ; Iterate for all numbers ; check for the last digit ; check for the largest left most digit ; print the rotation of array ; print the rotation of array ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void printLargest ( int a [ ] , int n ) { int max = -1 ; int ind = -1 ; for ( int i = 0 ; i < n ; i ++ ) { int num = a [ i ] ; while ( num ) { int r = num % 10 ; num = num / 10 ; if ( num == 0 ) { if ( max < r ) { max = r ; ind = i ; } } } } for ( int i = ind ; i < n ; i ++ ) cout << a [ i ] ; for ( int i = 0 ; i < ind ; i ++ ) cout << a [ i ] ; } int main ( ) { int a [ ] = { 54 , 546 , 548 , 60 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; printLargest ( a , n ) ; return 0 ; }