Answers for "find number given sum of digits and number of digits"

-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 "find number given sum of digits and number of digits"

Python Answers by Framework

Browse Popular Code Answers by Language