how to get sum of the digits of double

 
Hello i have a double number and i want to calculate the sum of the digits

for example 
33506 =====>  17 =====> 8
25822 =====>  19 =====> 10 ======> 1
 
  1. What's the point — it's meaningless.

  2. Your example shows an int not a double. Doubles have infinite digits right of the decimal point.

  3. Not compiled, not tested, just typed.

    int sum_of_digits(uint n){
       int sum=0;
       while(n>0){ sum += n % 10; n /= 10; }
       return sum < 10 ? sum : sum_of_digits(sum);
    }
    Not compiled, not tested, just typed.