right now I am trying to practice recursion, but I got stuck. The objective is to to sum up all the digits of the number. For example method's signature takes one int parameter. This parameter is number (for example 123). And recursively i should sum up 1+2+3 , and give an answer of 6.
So far I tried :
(It probably does not make sense, but I tried a lot)
public int sumofD(int n)
{
if (n == 0)
{ return 0; }
else
{
return n % 10 + sumofD(n-(n%10));
}
}