A remove-last-digit pattern prints an integer, then repeatedly strips the rightmost digit with integer division by 10 until the value becomes zero.
Remember
Rule: while num != 0 → print num → num = num / 10
86523
8652
865
86
8 ← start = 86523
Follows the hollow square border in Program 59; next is the growing reverse pattern in Program 61.
Approach
How to Solve It
Use a while loop: print the current value, then divide by 10. Stop when num reaches 0.
Method
Idea
Best for
while + divide by 10
Print, then num /= 10 until zero
Learning, interviews, digit drills
Abs for negatives
num = Math.Abs(num) before the loop
User input that may be negative
Pseudocode
Pseudocode
while num is not 0:
print num
num = num / 10
Cheat sheet
Goal
Pattern
Loop condition
while (num != 0)
Print current
Console.WriteLine(num);
Drop last digit
num = num / 10; or num /= 10;
Handle negatives
num = Math.Abs(num);
Line count
Equals the digit count of the starting number
Write vs WriteLine
API
Effect
Use for
Console.Write(num)
Stays on the same line
Rare here — values would glue together
Console.WriteLine(num)
Prints the value and ends the line
Each step of the pattern
Unlike nested triangle patterns, each iteration needs its own newline — so use WriteLine(num) every step.
Try it
Live Preview
Change the starting number and the digit-removal pattern updates instantly — absolute value, up to 9 digits.
Whole numbers from 1 to 999999999 (negatives use absolute value). Tap a chip or type a value.
Live resultnum = 86523 · 5 lines
86523
8652
865
86
8
Trace
Worked Walkthrough — num = 86523
Trace each print-then-divide step until the loop stops.
Step
Prints
After / 10
1
86523
8652
2
8652
865
3
865
86
4
86
8
5
8
0 (loop ends)
Five digits → five lines → O(d) time. Integer division truncates toward zero, so no floating-point is involved.
Code
C# Programs
Three complete programs: fixed num = 86523, TryParse input, and a compact num = 123 demo. Use View Output to reveal sample results.
Example 1 — Fixed num = 86523
Hard-coded start — print, then divide by 10 until zero.
C#
using System;
class Program
{
static void Main()
{
int num = 86523;
while (num != 0)
{
Console.WriteLine(num);
num = num / 10;
}
}
}
Output
86523
8652
865
86
8
How It Works
1. Print first. Show the current num before changing it.
2. Divide by 10. Integer division drops the last digit — 86523 / 10 is 8652.
3. Stop at zero. When num becomes 0, while (num != 0) ends.
Example 2 — User Input Number
Read num with int.TryParse, take absolute value, then run the same loop.
C#
using System;
class Program
{
static void Main()
{
Console.Write("Enter a number: ");
if (!int.TryParse(Console.ReadLine(), out int num))
{
Console.WriteLine("Please enter a valid integer.");
return;
}
num = Math.Abs(num);
while (num != 0)
{
Console.WriteLine(num);
num /= 10;
}
}
}
Output (when user enters 120)
Enter a number: 120
120
12
1
How It Works
1. Prompt and validate. Prefer TryParse so bad input does not throw.