are you ready to implement a few codes?if yes, then i guess you could do as follows--
say your sum i.e. 51 is stored in the variable x, i.e. x=51, initiate another variable say for instance A, and then follow these steps--
int A, B;
this loop will work if and only if x is an integer variable.
the working of the loop is as follows- since A is an integer variable, it can only store integer values, so while x/10 remains 5.1, the value stored in A will be 5 and then, B=x%10, the value of B will be 1(Since 51/10 leaves remainder 1)
this code can be changed as per your requirements.....
tell me if it works..........