Friday, April 19, 2013

10424 - Love Calculator

I didn't know I could simply the following: summing digits until the sum is a single digit.

while(sum > 9) {
     tempsum = sum;
     sum = 0;
     do {
         sum += tempsum%10;
         tempsum /= 10;
    } while(tempsum != 0);
}

to simply:

if(sum1%9==0)
   sum1=9;
else sum1%=9;

No comments:

Post a Comment