📜  C++ 对整数的数字求和 - C++ 代码示例

📅  最后修改于: 2022-03-11 14:44:50.376000             🧑  作者: Mango

代码示例2
// sum the digits of an integer
int getSum(long long n) {
  int sum = 0;
  int m = n;
  while(n > 0) {    
    m = n % 10;    
    sum = sum + m;    
    n = n / 10;    
  } 
  return sum;
}