[Solved] How to sum digits from integer in c++? [closed]


sum = n/100 + (n/10)%10 + n%10;

1) n/100
(n=123)
in this statement 123/100 means ans is = 1

2)(n/10)%10
here (123/10) firstly evaluate and ans is = 12, and then 12%10 gets evaluate and ans is = 2

3)n%10 again 123%10 evaluate ans is 3

then statement becomes

sum = 1 + 2 + 3

Note: % symbol gives remainder

solved How to sum digits from integer in c++? [closed]