Check out example codes for "calculate sum in c++". It will help you in understanding the concepts better.

Code Example 1

for (sum = 0; n > 0; sum += n % 10, n /= 10); //single line statement
                                              //where n=the imput number

Learn ReactJs, React Native from akashmittal.com