Answers for "compute sum of digits in all numbers from 1 to n in "x86""

0

sum the digits of an integer

def getSum(n)
  n.digits.sum
end

print "Sum of digits = ", getSum(555);
Posted by: Guest on May-27-2021
-2

sum the digits of an integer

#include <stdio.h>
 
int getSum(unsigned long long n) {
    int sum = 0;
    for (; n; n /= 10)
    	sum += n % 10;
    return sum;
}

int main(){
	printf("Sum of digits = %dn", getSum(555));
}
Posted by: Guest on May-27-2021

Code answers related to "compute sum of digits in all numbers from 1 to n in "x86""

Browse Popular Code Answers by Language