Our task is to print the alphabets from A to Z using loops. There are various methods to print alphabets from (A to Z) or (a to z).
- Using ASCII values
- Using character variables.
In this article we will mainly focus on the following programs and their logic:
- Using for loop
- Using the while loop
- Using a do-while loop
👁 Image
Program to display alphabets using ASCII values
OutputAlphabets from (A-Z) are:
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
Alphabets from (a-z) are:
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
Program to print (A to Z) and (a to z) using for loop
In the below program,
- For loop is used to print the alphabets from A to Z. A loop variable is taken to do this of type 'char'.
- The loop variable 'i' is initialized with the first alphabet 'A' and incremented by 1 on every iteration.
- In the loop, the character 'i' is printed as the alphabet.
Program:
OutputThe Alphabets from A to Z are:
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
The Alphabets from a to z are:
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
Program to print (A to Z) and (a to z) using the while loop
In the below program,
- While loop is used to print the alphabets from A to Z. A loop variable is taken to display of type 'char'.
- The loop variable 'i' is initialized with the first alphabet 'A' and incremented by 1 on every iteration.
- In the loop, the character 'i' is printed as the alphabet.
OutputThe Alphabets from A to Z are:
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
The Alphabets from a to z are:
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
Program to print (A to Z) and (a to z) using a do-while loop
In the below program,
- The do-while loop is used to print the alphabets from A to Z. A loop variable is taken to display of type 'char'.
- The loop variable 'i' is initialized with the first alphabet 'A' and incremented by 1 on every iteration.
- In the loop, the character 'i' is printed as the alphabet.
OutputThe Alphabets from A to Z are:
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
The Alphabets from a to z are:
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