How to Print A to Z in C (Using While & Do-While Loops)
Want to print A to Z in C? Let’s do it step by step using while and do-while loops.
It’s a simple program, but it helps you clearly understand how loops work with characters.
Uppercase letters are just A, B, C, D... up to Z.
In C, characters are stored as numbers (ASCII values), so we can easily move from one letter to the next using a loop.
What are uppercase alphabets in C?
Uppercase alphabets are characters from 'A' to 'Z'.
Each character has an ASCII value in the background.
For example, 'A' = 65 and 'Z' = 90.
That’s why we can use loops to print them one by one.
How to print A to Z in C?
The idea is very simple. Start from 'A', print it, then move to the next character.
Keep doing this until you reach 'Z'.
You can use either a while loop or a do-while loop—both will give the same result.
💻 C Program Code to Print A to Z Alphabets
📌 Output
Uppercase Alphabets from A to Z:
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
🧠 How This Program Works
- Step 1: Start with a character variable and assign it the value
'A'.
- Step 2: Use a loop that runs until the character reaches
'Z'.
- Step 3: Inside the loop, print the current character.
- Step 4: Increase the character value by 1 to move to the next alphabet.
- Step 5: Repeat the process until all letters from A to Z are printed.
⚡ Key Concept: Characters and ASCII Values
In C programming, characters like 'A', 'B', 'C' are stored using numeric values called
ASCII values. This means every character has a number behind it.
For example, 'A' = 65 and 'Z' = 90. When we increase a character
(like ch++), C automatically moves to the next letter. This is why we can use a loop
to print all alphabets from A to Z easily.
🚀 Practice Question
Now try these small changes on your own:
- Print lowercase alphabets from a to z
- Print alphabets in reverse order (Z to A)
- Print only vowels from A to Z (A, E, I, O, U)
Frequently Asked Questions (FAQs)
Q: How do you print A to Z in C using a while loop?
A: Start with a character variable set to 'A' and run a loop until it reaches 'Z'. Print the character in each step and increase it using ch++.
Q: Can I print alphabets in C without using ASCII values?
A: Yes. You can directly use characters like 'A' to 'Z'. C automatically handles their ASCII values in the background.
Q: What is the ASCII range for uppercase alphabets?
A: Uppercase letters have ASCII values from 65 ('A') to 90 ('Z').
Q: Which loop is better for this program – while or do-while?
A: Both work the same here. The only difference is that a do-while loop runs at least once before checking the condition.
Q: Why do we use ch++ in this program?
A: ch++ moves to the next character. For example, after 'A' it goes to 'B', then 'C', and so on.
Q: Is this program important for exams or interviews?
A: Yes. It’s a basic but very common question to test your understanding of loops and characters in C.
🔥 Print A to Z in C using Do-While Loop (Simple & Clear)
Let’s try a simple program to print uppercase alphabets from A to Z in C
using a do-while loop. This is a basic program and helps you understand
how loops work with characters.
In C, characters like A to Z are stored using ASCII values, so we can
easily loop from one character to another.
Code
📌 Output
Output:
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
🧠 Explanation (Easy)
We start from character 'A' and print it.
Then we move to the next character using ch++.
The loop keeps running until it reaches 'Z'.
Since this is a do-while loop, it runs at least once before checking the condition.