Two Legs
Left + right
Two diagonal scans meet at the bottom vertex.

Print letters only on the two diagonals that form a V, with spaces everywhere else. The last row prints a single vertex letter (E) because the right diagonal intentionally skips the last letter. Compare Program 20 (diagonal drills) and Program 21 (diamond symmetry). Includes a live preview, worked C examples, edge cases, and complexity.
Left + right
Two diagonal scans meet at the bottom vertex.
Main diagonal
Left leg prints only when row equals column.
Right starts at n-1
Right scan avoids duplicating the tip letter.
(n+1) + n
For A..E (n=4), each line spans 9 columns.
End letter
Pick an end letter (A–F) and draw the V.
Complexity
n rows × O(n) column scans each.
A V-shaped alphabet pattern places one letter on the main diagonal and one on a mirrored diagonal each row, filling the rest with spaces so the shape reads as a V in the console.
In C you walk row index i, scan left columns with i == j, then scan right columns from n-1 down so the tip letter prints once.
It locks in conditional diagonal printing and careful vertex handling — skills that transfer to X shapes, borders, and other sparse letter grids.
Print when i == j.
Scan k from n-1 to 0.
Fill non-diagonal cells.
Bottom vertex prints once.
In short: for each row i, scan left 0..n printing when i == j, then scan right n-1..0 printing when i == k, then call printf("\n").
Given an end letter (or fixed E), print a V of letters on two diagonals with spaces elsewhere and a single bottom vertex.
// Five rows (end = E, width 9)
// A A
// B B
// C C
// D D
// E | Item | Type | Description |
|---|---|---|
end / n | char / int | End letter; n = end - 'A' (4 for E). Rows = n+1. |
| Printed output | text | V of width 2n+1 with letters on diagonals and spaces elsewhere. |
n = end - 'A'
for i from 0 to n:
for j from 0 to n: // left leg
print (i == j ? letter[j] : " ")
for k from n-1 down to 0: // right leg (skip tip)
print (i == k ? letter[k] : " ")
print newline | Approach | Idea | Best for |
|---|---|---|
| Two diagonal scans | Left 0..n + right (n-1)..0 with i==col | Matching this classic sample |
| Single width loop | Map columns 0..(2n) to left/right conditions | One inner loop; same visuals |
| Goal | Pattern |
|---|---|
| Alphabet + n | char alpha[] = "ABCDEFG..."; int n = 4; |
| Rows | for (int i = 0; i <= n; i++) |
| Left leg | for (int j = 0; j <= n; j++) printf("%c", i == j ? alpha[j] : ' '); |
| Right leg | for (int k = n - 1; k >= 0; k--) printf("%c", i == k ? alpha[k] : ' '); |
| Symmetric pyramid next | See Program 32 |
Four roles that build the V without a double tip.
leftMain diagonal via i == j
rightMirrored leg; skips tip index
fillKeep columns aligned
breakEnds each full-width row
Reach for this when teaching sparse diagonal printing and a single shared vertex.
Step up from full letter rows to sparse diagonals.
Practice i == j with spaces for alignment.
Skip the tip on one leg so it prints once.
Next builds centered palindrome pyramids with spaces.
This is a console teaching pattern — not how you build modern app screens.
Key benefit: two diagonal scans with a right leg that starts at n-1 is the cleanest way to draw a V with a single tip letter.
Choose an end letter from A to F and draw the V-shaped alphabet pattern in the browser.
Three complete C programs — fixed A–E, scanf end letter, and a print_cell helper. Click View Output to reveal sample console results.
Print a five-row V with a single E at the tip.
Two scans per row: left-to-right (A..E) and right-to-left (D..A). Letters print only when the row matches the column.
#include <stdio.h>
int main() {
char alpha[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int i, j, k;
for (i = 0; i <= 4; i++) {
for (j = 0; j <= 4; j++) {
if (i == j)
printf("%c", alpha[j]);
else
printf(" ");
}
for (k = 3; k >= 0; k--) {
if (i == k)
printf("%c", alpha[k]);
else
printf(" ");
}
printf("\n");
}
return 0;
} When i = 2, the left scan prints C at column 2 and the right scan prints C when k = 2. On the last row, only the left scan can print E.
Let the user pick the end letter (like E).
The right scan starts at end - 1 so the vertex prints once. Check scanf and validate a single A–Z character in real apps.
#include <stdio.h>
int main() {
char alpha[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char end;
int n, i, j, k;
printf("Enter top letter (like E): ");
scanf(" %c", &end);
n = end - 'A';
for (i = 0; i <= n; i++) {
for (j = 0; j <= n; j++)
printf("%c", i == j ? alpha[j] : ' ');
for (k = n - 1; k >= 0; k--)
printf("%c", i == k ? alpha[k] : ' ');
printf("\n");
}
return 0;
} n = end - 'A' scales both scans. For end = C, width is 2×2+1 = 5 and the tip is a single C.
Same V with a shared cell helper for both legs.
Often clearer: one function applies the diagonal rule so left and right loops stay thin.
#include <stdio.h>
void print_cell(char alpha[], int row, int col) {
printf("%c", row == col ? alpha[col] : ' ');
}
int main() {
char alpha[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int n = 4;
int i, j, k;
for (i = 0; i <= n; i++) {
for (j = 0; j <= n; j++)
print_cell(alpha, i, j);
for (k = n - 1; k >= 0; k--)
print_cell(alpha, i, k);
printf("\n");
}
return 0;
} print_cell owns the row == col rule once. The right loop still starts at n - 1 to keep a single tip.
Row index i runs from 0..n which maps to A..end (A..E when n = 4).
Loop j = 0..n. Print the letter only when i == j; otherwise print a space.
Loop k = n-1..0 (D..A for E). Starting one below the tip keeps the last row as a single letter.
Left block has n+1 columns; right block has n columns. Total width is 2n+1 (9 for A..E).
Each row prints one letter on the left diagonal plus one on the right (except the last row) — O(n²) time.
Trace each row’s diagonal hits and the resulting 9-column line.
i | Left hit | Right hit | Printed row |
|---|---|---|---|
0 | A at j=0 | A at k=0 | A A |
1 | B at j=1 | B at k=1 | B B |
2 | C at j=2 | C at k=2 | C C |
3 | D at j=3 | D at k=3 | D D |
4 | E at j=4 | (none) | E |
Width is always 2×4+1 = 9. The tip row has no right-leg match because k never equals 4.
Where this V-shaped alphabet pattern shows up beyond the homework prompt.
Clearest demo of letter-only diagonals with space fill.
Example: temporarily print . instead of spaces to see columns.
Learn why one leg must skip the tip index.
Example: start right at n and watch a double E.
Practice n = end - 'A' with an alphabet array.
Example: scale from E to H without rewriting loops.
Factor the diagonal rule into print_cell (Example 3).
Example: reuse print_cell for an X-shaped variant later.
Full grid scans make O(n²) easy to see even when few letters print.
Example: 5 rows × 9 cells = 45 writes.
Next centers palindrome alphabet pyramids with leading spaces.
Example: continue to Program 32.
Pro Tip: say “left i==j, right i==k from n-1, spaces elsewhere” before coding — that story prevents a double tip.
Why this pattern earns a spot after filled alphabet rows.
A broken diagonal or double tip shows up immediately.
Both legs reuse row == col with spaces for fill.
Change n and the whole V grows.
print_cell keeps both legs short and readable.
Pro Tip: check alignment in a monospace font; proportional fonts make spaces look uneven.
Small habits that keep V-shaped alphabet patterns clean.
Starting at n duplicates the tip letter.
Skipping spaces collapses the V into packed letters.
Use n = end - 'A' so scaling stays automatic.
scanfRequire a single A–Z character; use toupper if needed.
Proportional fonts hide whether columns really align.
Pro Tip: if the last row shows E E, the right scan almost certainly started at k = n.
Mistakes that commonly break V-shaped alphabet patterns.
Duplicates the tip letter on the last row.
→ Start the right scan at k = n - 1.
Writing only letters collapses the V.
→ Print a space whenever row != col.
Char math can walk past the alphabet.
→ Validate a single A–Z letter.
scanfEmpty or multi-character input leaves end unused or only takes the first char.
→ Check scanf’s return value and require a single A–Z letter.
Comparing to the wrong index prints letters on the wrong diagonal.
→ Keep i == j / i == k against the current column.
Check these inputs before calling the solution done.
Output is just A (right leg empty).
5 rows × width 9 with tip E.
3 rows × width 5 (Example 2).
Convert lowercase with toupper from <ctype.h> if needed.
Check scanf’s return value before using end.
Temporarily print . instead of spaces.
Try these variations to lock in the pattern.
print_cellrow == col; otherwise print a space.2n + 1 (9 for A..E).Quick Takeaway: scan left with i == j, scan right from n-1 with i == k, fill spaces, skip a double tip, then break the line.
| Program | Time | Extra space |
|---|---|---|
| Inline / input (Examples 1–2) | O(n²) | O(1) (plus alphabet source) |
| Helper function (Example 3) | O(n²) | O(1) |
For n+1 letters there are n+1 rows and each row scans O(n) columns across both blocks, so total work is O(n²).
The V-shaped alphabet pattern is a sparse nested-loop exercise with lasting payoff: diagonal conditions, space fill for alignment, and a right leg that skips the tip so the vertex prints once. Master the classic A…E sample, then try user input and the helper rewrite.
Practice the three examples above, then continue to Program 32’s symmetric alphabet pyramid.
Left 0..n with i == j, right (n-1)..0 with i == k, spaces elsewhere, then break the line.
k = n - 1n from the end letterprintf("\n") inside either column loopPrint the V-shaped alphabet pattern the beginner-friendly way.
Diagonals + spaces
Definitioni == col
CodeStart at n-1
Code2n+1 columns
ShapeO(n²) time
AnalysisOuter i is the row index (A..E). Left scan prints only when i == j (main diagonal). Right scan runs from D down to A so the bottom vertex letter (E) appears once.
Next up: centered symmetric alphabet pyramids with palindromic rows like A, ABA, ABCBA, and ABCDEDCBA.
12 people found this page helpful