Example:
Input any number: 22464
Output:
Required knowledge
Basic C programming, LoopLogic to print the given number pattern
Printing these type of patterns are very simple. Logic to print the pattern is very simple, and is described below.- Print the value of num (where num is the number entered by user).
- Trim the last digit of num by dividing it from 10 i.e. num = num / 10.
- Repeat step 1-3 till the number is not equal to 0.
Program to print the given number pattern
/** * C program to print the given number pattern */ #include <stdio.h> int main() { int num; printf("Enter any number: "); scanf("%d", &num); while(num != 0) { printf("%d\n", num); num = num / 10; } return 0; }
Output
Enter any number: 12345
12345
1234
123
12
1
12345
1234
123
12
1
Screenshot
Happy coding ;)