Answers for "how to find sum of digits of the integer n when written in base B."

-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 = %d\n", getSum(555));
}
Posted by: Guest on May-27-2021

Code answers related to "how to find sum of digits of the integer n when written in base B."

Python Answers by Framework

Browse Popular Code Answers by Language