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

Count Occurrences of Digit 3

DEMO-C-32 • Programming in C

Browser-only practice

Problem Statement

Write a program that counts how many times the digit 3 appears in a given positive integer n. The program should read an integer n from standard input and output the count of digit 3 in n.

For example, if n = 32823, the digit 3 appears twice (at positions 0 and 4). If n = 124567, the digit 3 appears zero times. If n = 3333, the digit 3 appears four times.

Your solution should handle any positive integer that fits within the standard integer range.

Constraints

• Input integer n will be between 1 and 10^9 • The solution must handle large numbers efficiently • No additional memory allocation is required beyond basic variables

Input Format

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

Output Format

A single integer representing the count of digit 3 in n

Sample Testcases

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

Sample #1
Public sample
124567
0
The digit 3 does not appear in the number 124567
Sample #2
Public sample
3000
1
The digit 3 appears once in the number 3000, at the first position
Sample #3
Public sample
300000000
1
The digit 3 appears once in the number 300000000, at the first position
Sample #4
Public sample
13
1
The digit 3 appears once in the number 13
Sample #5
Public sample
3000000
1
The digit 3 appears once in the number 3000000000, at the first position
Sample #6
Public sample
313131313
5
The digit 3 appears five times in the number 313131313
Sample #7
Public sample
333333333
9
The digit 3 appears nine times in the number 333333333

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