Sum of Digits

Lab C Beginner 10 points

Read a non-negative integer and print the number of digits and the digit sum, using while.

Input

One integer.

Output

Two lines.

Example

Input

12345

Output

5
15
Sample input available Sample output available
Editor
C

Hints

A do-while runs at least once, which makes 0 count as one digit.

Solution explanation

do { } while (cond); checks the condition after the body.

Show solution
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    int count = 0, sum = 0;
    do {
        sum += n % 10;
        n /= 10;
        count++;
    } while (n > 0);
    printf("%d\n%d\n", count, sum);
    return 0;
}
Output
Answer
HOME LEARN COMMUNITY DASHBOARD