Digit Extractor - Problem

Given a 4-digit number, extract and print each digit separately on a new line.

For example, if the input is 1234, the output should be:

1
2
3
4

Each digit should be printed on its own line, starting from the leftmost (thousands place) to the rightmost (units place).

Input & Output

Example 1 — Basic 4-digit number
$ Input: number = 1234
Output: 1 2 3 4
💡 Note: Extract each digit: thousands=1, hundreds=2, tens=3, units=4. Print each on a new line.
Example 2 — Number with zeros
$ Input: number = 5067
Output: 5 0 6 7
💡 Note: Even with zero in hundreds place, each digit is extracted: 5, 0, 6, 7.
Example 3 — All same digits
$ Input: number = 7777
Output: 7 7 7 7
💡 Note: When all digits are the same, each position still outputs the same digit.

Constraints

  • 1000 ≤ number ≤ 9999
  • The input is guaranteed to be a 4-digit integer

Visualization

Tap to expand
INPUT12344-digit numberInput: 1234ALGORITHM11234 ÷ 1000 = 121234 ÷ 100 % 10 = 231234 ÷ 10 % 10 = 341234 % 10 = 4Extract each digit usingmathematical operationsRESULT1234Each digit onseparate lineKey Insight:Each digit position represents a power of 10. Division by that power isolates the digit.TutorialsPoint - Digit Extractor | Mathematical Division
Asked in
TCS 15 Infosys 12
12.0K Views
High Frequency
~5 min Avg. Time
450 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen