Diamond Repeating Numbers with Asterisks in C

What You’ll Learn
How to print a diamond repeating number pattern in C where each row repeats the same digit, separated by *.
The pattern grows from 1 to rows and then mirrors back down to 1.
⭐ Pattern Output
For rows = 5, the pattern looks like this:
1
2*2
3*3*3
4*4*4*4
5*5*5*5*5
4*4*4*4
3*3*3
2*2
1Complete C Program
Print an increasing half (1..rows), then a decreasing half (rows-1..1). Add * between repeated numbers.
#include <stdio.h>
int main() {
int rows = 5;
int i, j;
for (i = 1; i <= rows; i++) {
for (j = 1; j <= i; j++) {
printf("%d", i);
if (j != i) {
printf("*");
}
}
printf("\n");
}
for (i = rows - 1; i >= 1; i--) {
for (j = 1; j <= i; j++) {
printf("%d", i);
if (j != i) {
printf("*");
}
}
printf("\n");
}
return 0;
}🧠 How It Works
Print the upper half
The first outer loop runs from 1 to rows and prints 1 row per value.
Repeat the number with separators
The inner loop repeats the row value, and prints * between repeats (not after the last one).
Print the lower half
The second outer loop runs from rows-1 down to 1 to mirror the upper half.
Diamond mirror effect
Upper half grows, lower half shrinks, producing a symmetric pattern.
Variation — User Input Version
Read rows and generate the same diamond pattern.
#include <stdio.h>
int main() {
int rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);
int i, j;
for (i = 1; i <= rows; i++) {
for (j = 1; j <= i; j++) {
printf("%d", i);
if (j != i) {
printf("*");
}
}
printf("\n");
}
for (i = rows - 1; i >= 1; i--) {
for (j = 1; j <= i; j++) {
printf("%d", i);
if (j != i) {
printf("*");
}
}
printf("\n");
}
return 0;
}💡 Tips for Enhancement
Try These
- Replace
*with a different separator like-or| - Remove the separator to get 1, 22, 333, …
- Add spaces around separators for readability
- Print letters instead of numbers for an alphabet diamond
- Increase rows to create larger diamonds
Avoid
- Printing a trailing separator after the last number
- Forgetting the lower half loop (would not form a diamond)
- Not validating user input (rows <= 0)
- Mixing row value and repeat count (keep them consistent)
Key Takeaways
Two outer loops create the diamond: up then down.
The inner loop repeats the same value on each row.
A simple condition prevents printing a trailing *.
Mirroring patterns are common in diamond and hourglass shapes.
❓ Frequently Asked Questions
rows and then decreases back to 1. Each row repeats the same digit separated by *, producing a symmetric diamond-like output.printf("*") with any character like printf("-").Explore More C Number Patterns!
Mirror patterns like this are a stepping stone to diamonds and hourglass shapes.
Most diamond patterns are just two triangles back-to-back: one increasing, one decreasing. Once you see that, many pattern problems become much easier.
12 people found this page helpful
