Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

digit sum c++

//1
	int n = 12345, sum = 0;
    while(n) {
        sum+=n%10;
        n/=10;
    }
    cout << sum; //15
//2
	int n = 12345, sum = 0;
    for (sum = 0; n > 0; sum += n % 10, n /= 10);
    cout << sum; //15
 
PREVIOUS NEXT
Tagged: #digit #sum
ADD COMMENT
Topic
Name
8+7 =