Einfach 0 gelöst 0% Erfolgsquote

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.

Einschränkungen

1 ≤ n ≤ 10¹⁸

Beispiele

Beispiel 1
Eingabe:
n = 352

Erwartete Ausgabe:
expected = 10
Eingabe:
long long n = 352;

Erwartete Ausgabe:
long long expected = 10;
Eingabe:
long n = 352;

Erwartete Ausgabe:
long expected = 10;

Erläuterung

3 + 5 + 2 = 10.

Beispiel 2
Eingabe:
n = 1000

Erwartete Ausgabe:
expected = 1
Eingabe:
long long n = 1000;

Erwartete Ausgabe:
long long expected = 1;
Eingabe:
long n = 1000;

Erwartete Ausgabe:
long expected = 1;

Erläuterung

1 + 0 + 0 + 0 = 1.

Von anderen lernen

Community-Lösungen

Noch keine veröffentlichten Lösungen. Löse die Aufgabe und teile als Erster eine Lösung.