X

C Program to Display Characters from A to Z Using Loop

In this example, you will learn to print all the letters of the English alphabet.

Limited time offer: Get 10 free Adobe Stock images.ADS VIA CARBON

To understand this example, you should have the knowledge of the following C programming topics:


Program to Print English Alphabets

#include int main() { char c; for (c = 'A'; c <= 'Z'; ++c) printf("%c ", c); 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

In this program, the for loop is used to display the English alphabet in uppercase.

Here’s a little modification of the above program. The program displays the English alphabet in either uppercase or lowercase depending upon the input given by the user.


Print Lowercase/Uppercase alphabets

#include int main() { char c; printf("Enter u to display uppercase alphabets.\n"); printf("Enter l to display lowercase alphabets. \n"); scanf("%c", &c); if (c == 'U' || c == 'u') { for (c = 'A'; c <= 'Z'; ++c) printf("%c ", c); } else if (c == 'L' || c == 'l') { for (c = 'a'; c <= 'z'; ++c) printf("%c ", c); } else { printf("Error! You entered an invalid character."); } return 0; }

Output

Enter u to display uppercase alphabets. 
Enter l to display lowercase alphabets. l
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
Categories: Uncategorized
ilexjjtt-ca: