📅  最后修改于: 2022-03-11 14:48:25.609000             🧑  作者: Mango
//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