0

Runtime error

Don't know what's wrong having no output, if sum > 9. https://code.sololearn.com/cexB4F7bv8tw/?ref=app

22nd Feb 2020, 8:21 AM
Syed Waseem
Syed Waseem - avatar
4 Respostas
+ 1
I don't know what you want to do but if you want to add each element of any number then do like this :- while(x > 0) { rem=x%10; sum+=rem; x/=10; } return sum;
22nd Feb 2020, 8:39 AM
A͢J
A͢J - avatar
0
Could you please explain the code. What should the code do?
22nd Feb 2020, 8:40 AM
Avinesh
Avinesh - avatar
0
Avinesh It should print the sum of each single digits, If and only if sum is a single digit number. Ex : n=5347, sum= 5+3+4+7 = 19 ( having two digits, thus again take sum of current sum(19). Sum=1+9 = 10, Again take sum. Sum = 1+0 = 1 ( since sum is a single digit number, print sum = 1).
22nd Feb 2020, 8:51 AM
Syed Waseem
Syed Waseem - avatar
0
~ swim ~ Should I try making it local...
22nd Feb 2020, 8:53 AM
Syed Waseem
Syed Waseem - avatar