//1 int n = 12345, sum = 0; while(n) { sum+=n%10; n/=10; } cout << sum; //15 //2 int n = 12345, sum = 0; for (sum = 0; n > 0; sum += n % 10, n /= 10); cout << sum; //15