Previous
0 / 20
Module DEMO-32-59DEMO-C-32

Sum of Large Digits using while

DEMO-C-32 • Programming in C

Browser-only practice

Problem Statement

Write a C program that reads an integer and calculates the sum of all its digits that are greater than 5.

For example, if the input is 123456789, the digits greater than 5 are 6, 7, 8, and 9. Their sum is 6 + 7 + 8 + 9 = 30.

If there are no digits greater than 5 in the number, output 0.

Note: Handle negative numbers by ignoring the negative sign and working with the absolute value.

Constraints

-2,147,483,648 ≤ n ≤ 2,147,483,647 The program should handle negative numbers by considering their absolute value

Input Format

A single line containing an integer n (-2,147,483,648 ≤ n ≤ 2,147,483,647).

Output Format

A single line containing the sum of all digits in the number that are greater than 5.

Sample Testcases

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

Sample #1
Public sample
123456789
30
Digits greater than 5: 6, 7, 8, 9. Sum = 6+7+8+9 = 30
Sample #2
Public sample
987654321
30
Digits greater than 5: 9, 8, 7, 6. Sum = 9+8+7+6 = 30
Sample #3
Public sample
-123456789
30
Negative number. Consider absolute value: 123456789. Digits > 5: 6, 7, 8, 9. Sum = 30
Sample #4
Public sample
12345
0
No digits greater than 5. Sum = 0
Sample #5
Public sample
54321
0
No digits greater than 5. Sum = 0
Sample #6
Public sample
5
0
Single digit 5, which is not greater than 5. Sum = 0

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