can anybody help me , how to add digits within and array index..the problem is
Write a program that reads integer n followed by a sequence of n integers. Sort the integers of this sequence according to the sum of their digits.
For example, if the input data is
4
11111 321 39 45
The output will be
11111 321 45 39
Since the sum of their digits is 5, 6, 9 and 12 respectively.
char numbers[100][17]; //hold 100 number strings of unto 16 chars in length
int sums[100] = {0}; //hold the sums
//read the number of numbers to read
//main loop
cin >> numbers[curNumber];
for( i=0; i<strlen( numbers[curNumber] ); ++i )
sums[curNumber] += (toascii( numbers[curNumber][i] ) - toascii( '0' ));
//Sort both arrays
//end main loop
Of course this is one way of doing it, also it will only cater for 100 numbers entered (as string) and of length not exceeding 16.