Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python Program for Sum of the digits of a given number

# Python 3 program to
# compute sum of digits in
# number.
 
# Function to get sum of digits
 
 
def getSum(n):
 
    sum = 0
    while (n != 0):
 
        sum = sum + int(n % 10)
        n = int(n/10)
 
    return sum
 
 
# Driver code
n = 687
print(getSum(n))
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #python #Program #Sum #digits #number
ADD COMMENT
Topic
Name
8+2 =