Ram is given a positive integer N. He wishes to convert this integer into a single numeral . He does so by repeatedly adding the numerals of the number until there is only a single numeral . Help Ram by providing the single - numeral number finally obtained .
Input
The input is a single line containing a positive integer N.
Output
The output should be a single line containing a single-numeral number.
Explanation
In the example, the given number is 545.
As the number is more than a single numeral, repeatedly add the numerals like
5 + 4 + 5 => 14
1 + 4 => 5
So, the output should be 5.
Sample Input 1
545
Sample output 1
5
Sample Input 2
111
Sample output 2
3
sum = 10
number = int(input("Input number: "))
while (sum > 9):
sum = 0
while (number != 0):
sum = sum + number % 10
number = number // 10
number = sum
print("\nSingle numeral:", sum)
Comments
Leave a comment