Left-Shifted Odd Number Triangle in C

What You’ll Learn
How to print a left-shifted odd number triangle in C. Each new row starts from the next odd number but continues printing consecutive odd numbers to the end.
This pattern is a great way to practice step increments like i += 2 and j += 2.
⭐ Pattern Output
With odd numbers from 1 to 9, the output looks like this:
Output
13579
3579
579
79
91
Complete C Program
The outer loop sets the starting odd number for each row and the inner loop prints odd numbers up to 9.
c
#include <stdio.h>
int main() {
int i, j;
for (i = 1; i <= 10; i += 2) {
for (j = i; j <= 10; j += 2) {
printf("%d", j);
}
printf("\n");
}
return 0;
}2
Variation — User Input Version
Accept the maximum value from the user (odd numbers will be printed up to that max):
c
#include <stdio.h>
int main() {
int max;
int i, j;
printf("Enter the maximum value: ");
scanf("%d", &max);
for (i = 1; i <= max; i += 2) {
for (j = i; j <= max; j += 2) {
printf("%d", j);
}
printf("\n");
}
return 0;
}Explore More Number Patterns
Try changing the starting value or step size to create even-number and prime-number triangles.
Did you know?
Using += 2 is a simple and efficient way to iterate only odd numbers without any if condition checks inside the loop.
12 people found this page helpful
