The letter E star pattern prints a capital E with one straight stem and three bars: at the top, in the middle and at the bottom. It is one of the easiest letters, so it is a good one to start with.
Quick answer: Loop over 7 rows and 5 columns and print a star for the stem, the first column on every row, and for the three bars: row 1, the middle row and the last row. Everything else is a space, which leaves the right side of the letter open.
This program is part of the Star Patterns collection.
Table of contents8 sections
Letter E Star Pattern output
Output (7 rows):
***** * * ***** * * *****

How the letter e star pattern works
An E has four strokes, and each one is a whole row or a whole column. That makes the condition short: j == 1 for the stem and three row tests for the bars. Every letter on this site is drawn on a grid of rows and columns, and each stroke is one simple test on i and j.
- Run the outer loop for
ifrom1ton, one row per pass. - Go through
n ā 2positions in the row. Print stars wherej = 1 or i = 1 or i = n or i = (n + 1) / 2; print spaces everywhere else. - Move to the next line.
Key takeaways
- The stem is the first column on every row.
- The three bars are rows 1,
(n + 1) / 2andn. - Right-hand spaces on the stem rows are not printed, which keeps the output tidy.
- Dropping the bottom bar turns the E into an F.
Letter E Star Pattern in C
#include <stdio.h>
int main(void) {
int n = 7;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - 2; j++) {
if (j == 1 || i == 1 || i == n || i == (n + 1) / 2)
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}Letter E Star Pattern in C++
#include <iostream>
using namespace std;
int main() {
int n = 7;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - 2; j++) {
if (j == 1 || i == 1 || i == n || i == (n + 1) / 2)
cout << "*";
else
cout << " ";
}
cout << endl;
}
return 0;
}Letter E Star Pattern in Java
public class LetterEStar {
public static void main(String[] args) {
int n = 7;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - 2; j++) {
if (j == 1 || i == 1 || i == n || i == (n + 1) / 2)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
}
}Letter E Star Pattern in Python
n = 7
for i in range(1, n + 1):
for j in range(1, n - 2 + 1):
if j == 1 or i == 1 or i == n or i == (n + 1) // 2:
print("*", end="")
else:
print(" ", 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
How do I print the letter F?
Remove i == n from the condition. The bottom bar disappears and the stem continues on its own.
Why does the middle bar have the same length as the others?
All three bars fill the whole width. To make the middle one shorter, add j < n ā 3 to its test.
How do I let the user choose the size?
Read n from the keyboard instead of fixing it in the code: scanf("%d", &n); in C, cin >> n; in C++, new Scanner(System.in).nextInt() in Java and int(input()) in Python.










