Find the sum of the digits of a given number I need to find the sum of the digits of the given number and repeat the process until the value lies between 1 to 9. 

e.g
if the input is 72457 then, 

7+2+4+5+7 = 25

2+5 = 7

so , the function should return 7. 

Also, if the input is a negative number like -72457 the function should return -7.

Here's what i tried,

int digitSum(int input1){

int flag=0;

if(input1&lt;0)
     flag=1;

 int rem,sum=0;
 int x=abs(input1);

 while(x&gt;0){
    rem=x%10;
    sum+=rem;
    x=x/10;

    }

 int value = sum%9;

 if(value==0){

    if(flag==1)
     return -9;

    else
     return 9; 
 }

 else{

  if(flag==1)
   return -value;

   else
    return value;

 }

}
A simplified pure numerical function may be:

int digitSum(int input) {
    int n,m,s = input&lt;0 ? -1:1;
    for(n=input*s; n&gt;9; ) {
        for(m=n, n=0; m&gt;0; m/=10)
            n+=m%10;
    }
    return n*s;
}