.
int DigRoot(int n) { if (n<0) return -1; while (n>=10) { int sum=0; while (n>0) { sum+=n%10; n/=10; } n=sum; } return n; }