C++程序设计 Summing the digits in an integer

Description
Write a function that computes the sum of the digits in an integer. Use the following function header:

int sumDigits(long n)

For example, sumDigits(234) returns 9.

Hint
You should submit the implementation of the function but do not submit the main() function.
int 前拿胡sumDigits(long n)
{
    int res=0;
    while (n)
    {
        res+=n%10;
  慧拦      n/=10;
 敏余   }
    return res;
}