Program to find the sum of digits of a given number using a while loop in Python:
# While loop in Python - Sum of digits of a number
num = int(input("Enter a number: "))
sum = 0
while num > 0:
digit = num % 10
sum += digit
num //= 10
print("The sum of digits of the given number is:", sum)
Comments
Post a Comment