Question
Print the Alphabet (A to Z) using for loop in C Language
Solution
✔ Verified
This C program uses a for loop to print all uppercase letters of the English alphabet, from A to Z. In C, characters are represented using ASCII values. The character 'A' has the ASCII value 65, and 'Z' has the value 90.
The loop starts with the character variable ch initialized to 'A', and it runs until ch is less than or equal to 'Z'. In each iteration, the value of ch is printed, and then incremented to the next character in the alphabet using ch++.
This approach works because in C, characters can be compared and incremented just like integers due to their underlying ASCII representation.
#include <stdio.h>
int main() {
for (char ch = 'A'; ch <= 'Z'; ch++) {
printf("%c ", ch);
}
return 0;
}
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
Click here to download practice questions on
For Loop In C