Skip to content

Instantly share code, notes, and snippets.

@trhgquan
Created October 20, 2019 07:24
Show Gist options
  • Save trhgquan/be61313b440caba8be896ba4c2446922 to your computer and use it in GitHub Desktop.
Save trhgquan/be61313b440caba8be896ba4c2446922 to your computer and use it in GitHub Desktop.
For more algorithm, visit https://github.com/trhgquan/CPP
int root(int n) {
if (n >= 10) {
int s = 0;
while (n > 0) {
s += n % 10;
n /= 10;
}
return root(s);
}
return n;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment