Progressive Number Formation Pattern in C

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

What You’ll Learn

How to form a number step by step while extracting digits from right to left. Each line prints the intermediate value after appending the next digit.

⭐ Pattern Output

For num = 86523, the pattern looks like this:

Output
3
32
325
3256
32568
1

Complete C Program

Extract a digit with num % 10, append it using reverse = reverse * 10 + digit, print, and then remove the digit with num / 10.

c
#include <stdio.h>

int main() {
    int num = 86523;
    int reverse = 0;

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

    return 0;
}

🧠 How It Works

1

Extract last digit

num % 10 gives the rightmost digit (e.g., 86523 % 10 = 3).

Digit
2

Append to reverse

Multiply by 10 to shift, then add the digit: reverse = reverse * 10 + digit.

Build
3

Remove processed digit

num = num / 10 drops the last digit so we can process the next one.

Update
=

Progressive formation

One loop iteration per digit, so runtime is O(log n).

2

Variation — User Input Version

Read the number from the user with scanf().

c
#include <stdio.h>

int main() {
    int num;
    int reverse = 0;

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

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

    return 0;
}

💡 Tips for Enhancement

Try These

  • Print the final formed number after the loop ends
  • Count processed digits and print the count
  • Compare the final value with the original for palindrome checks

Avoid

  • Assuming this prints something for num=0 without handling it separately
  • Ignoring possible overflow for very large inputs (use long long if needed)

Key Takeaways

1

num % 10 extracts the last digit.

2

reverse = reverse * 10 + digit appends a digit.

3

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

4

Printing each step helps visualize number formation.

❓ Frequently Asked Questions

To shift existing digits left and make room for the next digit.
One per digit in the input number.
O(log₁₀ n).

Explore More C Number Patterns!

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

All Number Patterns →
Did you know?

num % 10 extracts the last digit, while num / 10 removes the last digit (integer division).

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