You are viewing a single comment's thread. Return to all comments →
C# Recursive:
static int superDigit(string n, int k) { StringBuilder sb = new StringBuilder(); for(int i = 0; i < k % 9; i++){ sb.Append(n); } return Helper(sb); } static int Helper(StringBuilder str){ if(str.Length == 1) return Convert.ToInt32(str.ToString()); else{ long sum = 0; for(int i = 0; i < str.Length; i++){ sum += Convert.ToInt32(str[i].ToString()); } return Helper(new StringBuilder(sum.ToString())); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Recursive Digit Sum
You are viewing a single comment's thread. Return to all comments →
C# Recursive: