Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

C++ sum the digits of an integer

// sum the digits of an integer
int getSum(long long n) {
  int sum = 0;
  int m = n;
  while(n > 0) {    
    m = n % 10;    
    sum = sum + m;    
    n = n / 10;    
  } 
  return sum;
}
 
PREVIOUS NEXT
Tagged: #sum #digits #integer
ADD COMMENT
Topic
Name
2+3 =