Reduce the digits:
You are given a positive integer N, write a program to repeatedly add the digits of the number until the number becomes a single-digit number.
Input:
The input should be a single line containing a single-digit number.
Output:
The output should be a single line containing a single-digit number.
Explanation:
In the example, the given number is 92. As the number is more than a single digit, repeatedly add the digits like
9+2=11
1+1=2
def digSum(n):
if (n == 0):
return 0
if (n % 9 == 0):
return 9
else:
return (n % 9)
# Driver program to test the above function
n = 92
print(digSum(n))
#Solved by J@$ur_h@ckeR
Comments
Leave a comment