✓ Link copied to clipboard
C 📅 July 5, 2026 ⏱ 1 min read

C Program to Display Characters from A to Z Using Loop

C Program to Display Characters from A to Z Using Loop

Printing the English alphabet from A to Z is a basic task that helps you get loops and character handling in C. This simple program uses a loop to go from A to Z. Let’s check out how to do this with a for loop.

Prerequisites for the C Program to Display Characters from A to Z

Before you write this program, make sure you're familiar with the following:

  • The for loop for iteration.
  • Basic character operations using ASCII values.
  • The <stdio.h> library for input/output functions.
  • Any C compiler such as GCC 9 or newer — or just run it in the EduSeekho online compiler.

Source Code of C Program to Display Characters from A to Z Using Loop

Here's the complete C code for this program:

display_alphabet.cC▶ Run
#include <stdio.h>

int main() {
    char ch = 'A';
    for (ch = 'A'; ch <= 'Z'; ch++) {
        printf("%c ", ch);
    }
    return 0;
}

Try this code yourself — free

Run it in the EduSeekho online compiler. No setup needed.

▶ Open Compiler

Output of the Display Characters A to Z Program

When you run this program, it prints the alphabet from A to Z:

TerminalOutput
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Output of C Program to Display Characters from A to Z Using Loop
Output of C Program to Display Characters from A to Z Using Loop

Algorithm to Display Characters from A to Z in C

Displaying characters from A to Z involves iterating through their ASCII values using a loop. Here is the exact logic, step by step:

  1. Initialize a character variable ch with the value 'A'.
  2. Use a for loop to iterate while ch is less than or equal to 'Z'.
  3. Inside the loop, print the current value of ch.
  4. Increment ch to move to the next character.
  5. Repeat steps 2-4 until ch exceeds 'Z'.
flowchart TD
  A([Start]) --> B[Initialize char ch = 'A']
  B --> C{"ch <= 'Z'?"}
  C -->|Yes| D[Print ch]
  D --> E[Increment ch]
  E --> C
  C -->|No| F([End])
Flowchart: the algorithm step by step

How the C Program to Display Characters from A to Z Works

Let's break down the program line by line to understand how it works:

  • The line #include <stdio.h> includes the standard input/output library, necessary for using printf.
  • The main() function is where the program execution begins.
  • We declare a char variable ch and initialize it with 'A'.
  • The for loop starts with ch = 'A', checks the condition ch <= 'Z', and increments ch after each iteration.
  • Inside the loop, printf("%c ", ch); prints the current character followed by a space.
  • When ch surpasses 'Z', the loop ends, and the program concludes with return 0;.
🧠

Quick Quiz — test your understanding

Tap an option to check your answer

What loop is typically used to display characters from A to Z in C?

🎉Correct! A for loop is ideal when the number of iterations is known.
🤔Not quite. Try a loop where you know the start and end conditions.

Time and Space Complexity of the C Program to Display Characters

Let's explore how efficient this program is in terms of performance:

Time Complexity: O(1). The loop runs a fixed number of 26 iterations, one for each letter in the English alphabet. The loop statement is for (ch = 'A'; ch <= 'Z'; ch++). It means the work doesn't grow — 26 iterations whether you run it today or tomorrow.

Space Complexity: O(1). The program uses a constant amount of memory — just the variable ch and a couple of control variables inside the loop which don't scale with input.

⚠️

Common mistake: Not incrementing the character variable ch in the loop leads to an infinite loop.

Key takeaway: Loops for handling character sequences efficiently is a basic skill in C programming.

FAQs About C Program to Display Characters from A to Z

Here are some common questions beginners have about this program:

Forgetting to increment ch would lead to an infinite loop since the condition ch <= 'Z' stays true forever.
Single quotes show character literals in C, which are different from string literals that use double quotes.
Yep, a while loop works too. But, a for loop's often better for its neat syntax when you know how many times to iterate.
The ASCII values for uppercase English letters go from 65 ('A') to 90 ('Z').
This method prints any sequence you define in the loop. For standard ASCII characters, you’re good up to 127.

If you found this program helpful, check out these related programs:

Conclusion

Printing characters from A to Z gives you a nice start with loops in C. Once you’re comfy, try changing the range to print lowercase or numeric characters. This skill’s super useful for creating simple text-based games or apps. As you move on, think about diving into more string manipulations in C.

Practice more with the C language quiz and give your programs a spin in the EduSeekho online compiler.