Problema
Mostra originale (inglese)Somma tutte le cifre decimali di n. Per 352 le cifre sono 3, 5 e 2.
Implementa sum_of_digits(n).
Input
n: Un intero positivo.
Output
Restituisci la somma delle sue cifre.
Vincoli
1 ≤ n ≤ 10¹⁸
Esempi
Esempio 1
Input:
n = 352
Output atteso:
expected = 10
Input:
long long n = 352;
Output atteso:
long long expected = 10;
Input:
long n = 352;
Output atteso:
long expected = 10;
Spiegazione
3 + 5 + 2 = 10.
Esempio 2
Input:
n = 1000
Output atteso:
expected = 1
Input:
long long n = 1000;
Output atteso:
long long expected = 1;
Input:
long n = 1000;
Output atteso:
long expected = 1;
Spiegazione
1 + 0 + 0 + 0 = 1.