0010 - Suma Cifrelor: Difference between revisions
Pop Giulia (talk | contribs) |
Pop Giulia (talk | contribs) |
||
Line 1: | Line 1: | ||
numar = int(input("Introduceti un numar natural: ")) | |||
suma_cifre = 0 | |||
while numar > 0: | |||
cifra = numar % 10 | |||
suma_cifre += cifra | |||
numar //= 10 | |||
print("Suma cifrelor este:", suma_cifre) |
Revision as of 11:57, 1 April 2023
numar = int(input("Introduceti un numar natural: ")) suma_cifre = 0 while numar > 0:
cifra = numar % 10 suma_cifre += cifra numar //= 10
print("Suma cifrelor este:", suma_cifre)