Number Pattern with Right Digit Removal in C

Beginner
⏱️ 5 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
While Loop

What You’ll Learn

How to print a decreasing pattern by repeatedly removing the rightmost digit from a number using integer division (num / 10).

⭐ Pattern Output

For num = 86523, the pattern looks like this:

Output
86523
8652
865
86
8
1

Complete C Program

Print the number, then do num = num / 10 until it becomes 0.

c
#include <stdio.h>

int main() {
    int num = 86523;

    while (num != 0) {
        printf("%d\n", num);
        num = num / 10;
    }

    return 0;
}

🧠 How It Works

1

Start with a number

num holds the current value to print.

Setup
2

Print and divide by 10

After printing, num = num / 10 removes one digit from the right.

Update
3

Stop at zero

When the number becomes 0, there are no digits left to remove.

Stop
=

Right-digit removal

One loop iteration per digit, so runtime grows with the number of digits.

2

Variation — User Input Version

Read the starting number from the user using scanf().

c
#include <stdio.h>

int main() {
    int num;

    printf("Enter a number: ");
    scanf("%d", &num);

    while (num != 0) {
        printf("%d\n", num);
        num = num / 10;
    }

    return 0;
}

💡 Tips for Enhancement

Try These

  • Count digits removed and print the count per line
  • Store values and print them bottom-up for a reversed pattern
  • Extract digits using num % 10 before dividing

Avoid

  • Using negative numbers without handling sign
  • Assuming this prints something for num = 0 (it won’t)

Key Takeaways

1

Integer division by 10 removes the last digit.

2

The loop runs once per digit: O(log n).

3

Stopping at num != 0 ends after the last single digit is printed.

4

This technique is useful for digit-manipulation problems.

❓ Frequently Asked Questions

Because integer division truncates. The remainder is dropped, so the last digit disappears.
The loop won’t run. If you want to print 0, handle it as a special case before the loop.
O(log₁₀ n) for n.

Explore More C Number Patterns!

Try more digit-manipulation patterns and loop-based variations.

All Number Patterns →
Did you know?

Dividing by 10 removes the last digit, while num % 10 extracts the last digit.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful