問題
翻訳を表示Add up every decimal digit of n. For 352 the digits are 3, 5 and 2.
Implement sum_of_digits(n).
Input
n: A positive integer.
Output
Return the sum of its digits.
制約
1 ≤ n ≤ 10¹⁸
例
例 1
入力:
n = 352
期待される出力:
expected = 10
入力:
long long n = 352;
期待される出力:
long long expected = 10;
入力:
long n = 352;
期待される出力:
long expected = 10;
解説
3 + 5 + 2 = 10.
例 2
入力:
n = 1000
期待される出力:
expected = 1
入力:
long long n = 1000;
期待される出力:
long long expected = 1;
入力:
long n = 1000;
期待される出力:
long expected = 1;
解説
1 + 0 + 0 + 0 = 1.