Previous Next
0 / 18
Module DEMO-32-91DEMO-C-32

Digit Sum Calculator

DEMO-C-32 • Programming in C

Browser-only practice

Problem Statement

Write a program that calculates the sum of all digits in a given positive integer.

For example, if the input is 1234, the digits are 1, 2, 3, and 4. The sum would be 1 + 2 + 3 + 4 = 10.

Your program should read a positive integer from standard input and output the sum of its digits.

Constraints

1 ≤ N ≤ 10^9 The number will not have leading zeros

Input Format

A single line containing a positive integer N (1 ≤ N ≤ 10^9).

Output Format

A single line containing the sum of all digits in the input number.

Sample Testcases

Submit runs every public testcase in this browser. Results and code never leave this device.

Sample #1
Public sample
1234
10
Sample case: 1+2+3+4 = 10
Sample #2
Public sample
1000
1
Number with zeros
Sample #3
Public sample
2048
14
Number with zeros in middle: 2+0+4+8 = 14
Sample #4
Public sample
123456789
45
All digits from 1 to 9: 1+2+3+4+5+6+7+8+9 = 45

Web terminal

C, C++, Java, and Python run locally in a browser VM. No worker or visualizer is used.

Saved in this browser
Editor settings