The descending repeated number triangle grows like a normal triangle, but its digits go down: 5, 44, 333, 2222, 11111. The longest row is made of 1s.
Quick answer: Keep the normal triangle loops, with row i printing i characters, and print the value n β i + 1 each time. The row length goes up while the digit goes down, so the bottom row is five 1s.
This program is part of the Number Patterns collection.
Table of contents8 sections
- Descending Repeated Number Triangle output
- How the descending repeated number triangle works
- Descending Repeated Number Triangle in C
- Descending Repeated Number Triangle in C++
- Descending Repeated Number Triangle in Java
- Descending Repeated Number Triangle in Python
- Time and space complexity
- Frequently asked questions
Descending Repeated Number Triangle output
Output (n = 5):
5 44 333 2222 11111

Same shape, other characters: the Alternating Star and Hash Triangle, Descending Number Triangle, Number Right Triangle, Repeated Number Triangle and Reverse Number Triangle programs draw this same outline with different characters. Putting them side by side shows which part of the loop decides the shape and which part decides what is printed.
How the descending repeated number triangle works
Two things change from row to row and they move in opposite directions. The count follows i, which is what gives the triangle its shape. The digit follows n β i + 1, which counts down. Keeping those two ideas apart, shape from the loop and value from the formula, is the habit that makes every number pattern easier.
- Run the outer loop for
ifrom1ton, one row per pass. - Print
inumbers (valuen β i + 1). - Move to the next line.
Key takeaways
- The shape comes from the loop and the digit from the formula.
- The count grows with
iwhile the digit shrinks withn β i + 1. - The digits on a row never change, so the inner loop ignores
j. - Pairs well with the repeated number triangle (1, 22, 333) for practice.
Descending Repeated Number Triangle in C
#include <stdio.h>
int main(void) {
int n = 5;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++)
printf("%d", n - i + 1);
printf("\n");
}
return 0;
}Descending Repeated Number Triangle in C++
#include <iostream>
using namespace std;
int main() {
int n = 5;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++)
cout << n - i + 1;
cout << endl;
}
return 0;
}Descending Repeated Number Triangle in Java
public class DescendingRepeatedNumberTriangle {
public static void main(String[] args) {
int n = 5;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++)
System.out.print(n - i + 1);
System.out.println();
}
}
}Descending Repeated Number Triangle in Python
n = 5
for i in range(1, n + 1):
for j in range(1, i + 1):
print(n - i + 1, end="")
print()Time and space complexity
The program prints one character for each position in the pattern, so for n rows it runs in O(nΒ²) time. It only needs a few loop variables, so the extra memory is O(1).
Frequently asked questions
Why is the bottom row all 1s?
On the last row i = n, so the value n β i + 1 is 1, and the row has n positions. That gives five 1s for n = 5.
How do I right-align the triangle?
Print n β i spaces before the digits. The rows then end in the same column, like the mirrored number triangle.
What changes for n = 12?
The first rows print 12 and 11, which have two digits, so they look twice as long as intended. Add a space after each number, or keep n below 10.






