0010 - Suma Cifrelor: Difference between revisions

From Bitnami MediaWiki
Pop Giulia (talk | contribs)
No edit summary
Pop Giulia (talk | contribs)
Line 1: Line 1:
numar = int(input("Introduceti un numar: "))
Se da un numar natural. Calculaţi suma cifrelor numărului dat.
suma = 0
 
while numar > 0:
    cifra = numar % 10
    suma += cifra
    numar = numar // 10
 
print("Suma cifrelor numarului este: ", suma)

Revision as of 11:55, 1 April 2023

Se da un numar natural. Calculaţi suma cifrelor numărului dat.