Skip to content

Commit e27802f

Browse files
authored
Sumoffigitswithoutanyloop
Finding Sum off digits of a number untill the sum is singular,without any loops
1 parent 33f5116 commit e27802f

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

algorithms/math/sumofdigits.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#This is to find the sum of digits of a number untill it is a single digit
2+
n=int(input()) #here n is the number
3+
if n%9!=0:
4+
print(n%9)
5+
else:
6+
print("9")
7+
#this method reduces time complexity by a factor of n and also without using any loop
8+

0 commit comments

Comments
 (0)