human
Sort the numbers according to their sum of digits | Function to return the sum of the digits of n.
Function to sort the array according to the sum of the digits of elements.
Vector to store digit sum with respective element.
Inserting digit sum with element in the vector pair.
Quick sort the vector , this will sort the pair according to sum of the digits of elements.
Print the sorted vector content.
Driver code"
Solution in Python:
assistant
#Here is code to sort the numbers according to their sum of digits and the other steps required.
 def sumOfDigit ( n ) :
	sum = 0 ;
	while ( n > 0 ) :
		sum += n % 10 ;
		n = n // 10 ;
	return sum ;
def sortArr ( arr , n ) :
	vp = [ ] ;
	for i in range ( n ) :
		vp . append ( [ sumOfDigit ( arr [ i ] ) , arr [ i ] ] ) ;
	vp . sort ( )
	for i in range ( len ( vp ) ) :
		print ( vp [ i ] [ 1 ] , end = " ▁ " ) ;
if __name__ == " _ _ main _ _ " :
	arr = [ 14 , 1101 , 10 , 35 , 0 ] ;
	n = len ( arr ) ;
	sortArr ( arr , n ) ;