Number pattern 47 in C

Write a C program to print the given number pattern using loop. How to print the given triangular number pattern series using for loop in C programming. Logic to print the given number pattern using C program.



Input any number: 24165


Required knowledge

Basic C programming, Loop

Logic to print the given number pattern

The given number pattern is similar to the previous number pattern. Also logic of this pattern would be very much similar to the previous pattern.

Must know -

Logic to print the given pattern is.

  1. Print the value of num (where num is the number entered by user).
  2. Remove the first digit of the number, as it isn't needed anymore.
  3. Repeat steps 1-3 till the number is greater than 0.

Program to print the given number pattern

 * C program to print the given number pattern

#include <stdio.h>
#include <math.h>

int main()
    int num, firstDigit, digits, placeValue;

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

    while(num > 0)
        printf("%d\n", num);

        digits = (int) log10(num);                // Get total number of digits
        placeValue = (int) ceil(pow(10, digits)); // Get the place value of first digit
        firstDigit = (int)(num / placeValue);     // Get the first digit

        num = num - (placeValue * firstDigit);    // Remove first digit from number

    return 0;


Enter any number: 24165

Happy coding 😉

About Pankaj

Pankaj Prakash is the founder, editor and blogger at Codeforwin. He loves to learn new techs and write programming articles especially for beginners. He works at Vasudhaika Software Sols. as a Software Design Engineer and manages Codeforwin. In short Pankaj is Web developer, Blogger, Learner, Tech and Music lover.

Follow on: Twitter | Google | or

Comments and discussion
Have a doubt, write here. I will help my best.
Before commenting you must escape your source code before commenting. Paste your source code inside
<pre><code> ----Your Source Code---- </code></pre>