For your interview preparation, I created all-in-one solutions for different varieties of number patterns in C, Java, and Python.
1. Pattern: Descending Number Triangle
Expected output:
12345
1234
123
12
1
Solution in C Program:
#include <stdio.h> int main() { // Outer loop for the number of rows for (int i = 5; i >= 1; i--) { // Inner loop for printing numbers from 1 to i for (int j = 1; j <= i; j++) { printf("%d", j); // Print the current number } printf("n"); // Move to the next line after each row } return 0; }
Solution in Java:
public class NumberPattern { public static void main(String[] args) { // Outer loop for the number of rows for (int i = 5; i >= 1; i--) { // Inner loop for printing numbers from 1 to i for (int j = 1; j <= i; j++) { System.out.print(j); // Print the current number } System.out.println(); // Move to the next line after each row } } }
Solution in Python:
# Outer loop for the number of rows for i in range(5, 0, -1): # Inner loop for printing numbers from 1 to i for j in range(1, i + 1): print(j, end='') # Print the current number, stay on the same line print() # Move to the next line after each row
2. Pattern: Descending Number Triangle
Expected output:
54321
4321
321
21
1
Solution in C Program:
#include <stdio.h> int main() { // Outer loop for the number of rows (starting from 5 down to 1) for (int i = 5; i >= 1; i--) { // Inner loop to print numbers from i down to 1 for (int j = i; j >= 1; j--) { printf("%d", j); // Print the current number } printf("n"); // Move to the next line after each row } return 0; }
Solution in Java:
public class NumberPattern { public static void main(String[] args) { // Outer loop for the number of rows (starting from 5 down to 1) for (int i = 5; i >= 1; i--) { // Inner loop to print numbers from i down to 1 for (int j = i; j >= 1; j--) { System.out.print(j); // Print the current number } System.out.println(); // Move to the next line after each row } } }
Solution in Python:
# Outer loop for the number of rows (starting from 5 down to 1) for i in range(5, 0, -1): # Inner loop to print numbers from i down to 1 for j in range(i, 0, -1): print(j, end='') # Print the current number, stay on the same line print() # Move to the next line after each row
3. Pattern: Descending Number Triangle (Modified)
Expected output:
12345
2345
345
45
5
Solution in C Program:
#include <stdio.h> int main() { // Outer loop for the number of rows (starting from 1 to 5) for (int i = 1; i <= 5; i++) { // Inner loop to print numbers starting from i to 5 for (int j = i; j <= 5; j++) { printf("%d", j); // Print the current number } printf("n"); // Move to the next line after each row } return 0; }
Solution in Java:
public class NumberPattern { public static void main(String[] args) { // Outer loop for the number of rows (starting from 1 to 5) for (int i = 1; i <= 5; i++) { // Inner loop to print numbers starting from i to 5 for (int j = i; j <= 5; j++) { System.out.print(j); // Print the current number } System.out.println(); // Move to the next line after each row } } }
Solution in Python:
# Outer loop for the number of rows (starting from 1 to 5) for i in range(1, 6): # Inner loop to print numbers starting from i to 5 for j in range(i, 6): print(j, end='') # Print the current number, stay on the same line print() # Move to the next line after each row
4. Pattern: Descending Number Triangle (Modified)
Expected output:
54321
5432
543
54
5
Solution in C Program:
#include <stdio.h> int main() { // Outer loop for the number of rows (starting from 5 down to 1) for (int i = 5; i >= 1; i--) { // Inner loop to print numbers starting from 5 down to i for (int j = 5; j >= 6 - i; j--) { printf("%d", j); // Print the current number } printf("n"); // Move to the next line after each row } return 0; }
Solution in Java:
public class NumberPattern { public static void main(String[] args) { // Outer loop for the number of rows (starting from 5 down to 1) for (int i = 5; i >= 1; i--) { // Inner loop to print numbers starting from 5 down to i for (int j = 5; j >= 6 - i; j--) { System.out.print(j); // Print the current number } System.out.println(); // Move to the next line after each row } } }
Solution in Python:
# Outer loop for the number of rows (starting from 5 down to 1) for i in range(5, 0, -1): # Inner loop to print numbers starting from 5 down to i for j in range(5, 6 - i, -1): print(j, end='') # Print the current number, stay on the same line print() # Move to the next line after each row
5. Pattern: Ascending Number Triangle
Expected output:
1
21
321
4321
54321
Solution in C Program:
#include <stdio.h> int main() { // Outer loop for the number of rows (starting from 1 to 5) for (int i = 1; i <= 5; i++) { // Inner loop to print numbers starting from i down to 1 for (int j = i; j >= 1; j--) { printf("%d", j); // Print the current number } printf("n"); // Move to the next line after each row } return 0; }
Solution in Java:
public class NumberPattern { public static void main(String[] args) { // Outer loop for the number of rows (starting from 1 to 5) for (int i = 1; i <= 5; i++) { // Inner loop to print numbers starting from i down to 1 for (int j = i; j >= 1; j--) { System.out.print(j); // Print the current number } System.out.println(); // Move to the next line after each row } } }
Solution in Python:
# Outer loop for the number of rows (starting from 1 to 5) for i in range(1, 6): # Inner loop to print numbers starting from i down to 1 for j in range(i, 0, -1): print(j, end='') # Print the current number, stay on the same line print() # Move to the next line after each row
6. Pattern: Ascending Number Triangle
Expected output:
1
12
123
1234
12345
Solution in C Program:
#include <stdio.h> int main() { // Outer loop for the number of rows (starting from 1 to 5) for (int i = 1; i <= 5; i++) { // Inner loop to print numbers from 1 to i for (int j = 1; j <= i; j++) { printf("%d", j); // Print the current number } printf("n"); // Move to the next line after each row } return 0; }
Solution in Java:
public class NumberPattern { public static void main(String[] args) { // Outer loop for the number of rows (starting from 1 to 5) for (int i = 1; i <= 5; i++) { // Inner loop to print numbers from 1 to i for (int j = 1; j <= i; j++) { System.out.print(j); // Print the current number } System.out.println(); // Move to the next line after each row } } }
Solution in Python:
# Outer loop for the number of rows (starting from 1 to 5) for i in range(1, 6): # Inner loop to print numbers from 1 to i for j in range(1, i + 1): print(j, end='') # Print the current number, stay on the same line print() # Move to the next line after each row
7. Pattern: Descending Number Triangle (Modified)
Expected output:
5
54
543
5432
54321
Solution in C Program:
#include <stdio.h> int main() { // Outer loop for the number of rows (starting from 1 to 5) for (int i = 1; i <= 5; i++) { // Inner loop to print numbers starting from 5 down to (5 - i + 1) for (int j = 5; j >= 6 - i; j--) { printf("%d", j); // Print the current number } printf("n"); // Move to the next line after each row } return 0; }
Solution in Java:
public class NumberPattern { public static void main(String[] args) { // Outer loop for the number of rows (starting from 1 to 5) for (int i = 1; i <= 5; i++) { // Inner loop to print numbers starting from 5 down to (5 - i + 1) for (int j = 5; j >= 6 - i; j--) { System.out.print(j); // Print the current number } System.out.println(); // Move to the next line after each row } } }
Solution in Python:
# Outer loop for the number of rows (starting from 1 to 5) for i in range(1, 6): # Inner loop to print numbers starting from 5 down to (5 - i + 1) for j in range(5, 6 - i, -1): print(j, end='') # Print the current number, stay on the same line print() # Move to the next line after each row
8. Pattern: Modified Ascending Number Triangle
Expected output:
5
45
345
2345
12345
Solution in C Program:
#include <stdio.h> int main() { // Outer loop for the number of rows (starting from 1 to 5) for (int i = 5; i >= 1; i--) { // Inner loop to print numbers starting from i to 5 for (int j = i; j <= 5; j++) { printf("%d", j); // Print the current number } printf("n"); // Move to the next line after each row } return 0; }
Solution in Java:
public class NumberPattern { public static void main(String[] args) { // Outer loop for the number of rows (starting from 5 down to 1) for (int i = 5; i >= 1; i--) { // Inner loop to print numbers starting from i to 5 for (int j = i; j <= 5; j++) { System.out.print(j); // Print the current number } System.out.println(); // Move to the next line after each row } } }
Solution in Python:
# Outer loop for the number of rows (starting from 5 down to 1) for i in range(5, 0, -1): # Inner loop to print numbers starting from i to 5 for j in range(i, 6): print(j, end='') # Print the current number, stay on the same line print() # Move to the next line after each row
9. Pattern: Repetitive Number Triangle
Expected output:
1
22
333
4444
55555
Solution in C Program:
#include <stdio.h> int main() { // Outer loop for the number of rows (starting from 1 to 5) for (int i = 1; i <= 5; i++) { // Inner loop to print the number i, i times for (int j = 1; j <= i; j++) { printf("%d", i); // Print the current number i } printf("n"); // Move to the next line after each row } return 0; }
Solution in Java:
public class NumberPattern { public static void main(String[] args) { // Outer loop for the number of rows (starting from 1 to 5) for (int i = 1; i <= 5; i++) { // Inner loop to print the number i, i times for (int j = 1; j <= i; j++) { System.out.print(i); // Print the current number i } System.out.println(); // Move to the next line after each row } } }
Solution in Python:
# Outer loop for the number of rows (starting from 1 to 5) for i in range(1, 6): # Inner loop to print the number i, i times for j in range(i): print(i, end='') # Print the current number i, stay on the same line print() # Move to the next line after each row
10. Pattern: Descending Repetitive Number Triangle
Expected output:
55555
4444
333
22
1
Solution in C Program:
#include <stdio.h> int main() { // Outer loop for the number of rows (starting from 5 to 1) for (int i = 5; i >= 1; i--) { // Inner loop to print the number i, i times for (int j = 1; j <= i; j++) { printf("%d", i); // Print the current number i } printf("n"); // Move to the next line after each row } return 0; }
Solution in Java:
public class NumberPattern { public static void main(String[] args) { // Outer loop for the number of rows (starting from 5 down to 1) for (int i = 5; i >= 1; i--) { // Inner loop to print the number i, i times for (int j = 1; j <= i; j++) { System.out.print(i); // Print the current number i } System.out.println(); // Move to the next line after each row } } }
Solution in Python:
# Outer loop for the number of rows (starting from 5 down to 1) for i in range(5, 0, -1): # Inner loop to print the number i, i times for j in range(i): print(i, end='') # Print the current number i, stay on the same line print() # Move to the next line after each row
11. Pattern:
Expected output:
5
44
333
2222
11111
Solution in C Program:
#include <stdio.h> int main() { // Outer loop for the number of rows (starting from 5 down to 1) for (int i = 5; i >= 1; i--) { // Inner loop to print the number i, i times for (int j = 1; j <= i; j++) { printf("%d", i); // Print the current number i } printf("n"); // Move to the next line after each row } return 0; }
Solution in Java:
public class NumberPattern { public static void main(String[] args) { // Outer loop for the number of rows (starting from 5 down to 1) for (int i = 5; i >= 1; i--) { // Inner loop to print the number i, i times for (int j = 1; j <= i; j++) { System.out.print(i); // Print the current number i } System.out.println(); // Move to the next line after each row } } }
Solution in Python:
# Outer loop for the number of rows (starting from 5 down to 1) for i in range(5, 0, -1): # Inner loop to print the number i, i times for j in range(i): print(i, end='') # Print the current number i, stay on the same line print() # Move to the next line after each row
12. Pattern: Descending Repetitive Number Triangle (Modified)
Expected output:
11111
2222
333
44
5
Solution in C Program:
#include <stdio.h> int main() { // Outer loop for the number of rows (starting from 5 down to 1) for (int i = 1; i <= 5; i++) { // Inner loop to print the number i, 6 - i times for (int j = 1; j <= 6 - i; j++) { printf("%d", i); // Print the current number i } printf("n"); // Move to the next line after each row } return 0; }
Solution in Java:
public class NumberPattern { public static void main(String[] args) { // Outer loop for the number of rows (starting from 1 to 5) for (int i = 1; i <= 5; i++) { // Inner loop to print the number i, 6 - i times for (int j = 1; j <= 6 - i; j++) { System.out.print(i); // Print the current number i } System.out.println(); // Move to the next line after each row } } }
Solution in Python:
# Outer loop for the number of rows (starting from 1 to 5) for i in range(1, 6): # Inner loop to print the number i, 6 - i times for j in range(6 - i): print(i, end='') # Print the current number i, stay on the same line print() # Move to the next line after each row
Hope you find them helpful for your interview preparation in a good way.
©️ 2025, Number patterns in C, Java, and Python programming language by Rakshit Shah (Author).
You may also like,
3. Hard Number Patterns in C, Java, and Python Programming [Interview Questions]
Discover more from 9Mood
Subscribe to get the latest posts sent to your email.
0 Comments