ง่าย 0 ข้อที่แก้แล้ว อัตราผ่าน 0%

Sum of Digits

Add up the decimal digits of a positive integer.

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.

เรียนรู้จากคนอื่น

แนวทางจากชุมชน

ยังไม่มีวิธีทำที่เผยแพร่ ลองแก้โจทย์นี้เพื่อแชร์วิธีแรก