We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Recursive Digit Sum
- Discussions
Recursive Digit Sum
Recursive Digit Sum
Sort by
recency
|
178 Discussions
|
Please Login in order to post a comment
C# Note: Watch out for integer overflow and multiplying n by k - I found multiplying the sum of n by k worked out rather than concatenating n for k times to work.
My TypeScript code. Tried to shorten it but still kinda messy. Feedbacks are welcome.
my code won't passing test case7,8&9; can anyone debug it;
public static int recursion(int sum) { int r=0; if(sum<=9&&sum>0) return sum; else{ while(sum!=0 ) { r=r+sum%10; sum=sum/10; } return recursion(r); }
}
Solution in Python3: