How to write a C Program to Print Alphabets from a to z using For Loop and While Loop.
C Program to Print Alphabets from a to z using For Loop
This program will print alphabets from a to z using For Loop. Here, For Loop will make sure that the character (ch) is between a and z.
/* C Program to Print Alphabets from a to z */ #include <stdio.h> int main() { char ch; printf("\n List of Alphabets from a to z are : \n"); for(ch = 'a'; ch <= 'z'; ch++) { printf(" %c\t", ch); } return 0; }
C Program to display Alphabets from a to z using ASCII Codes
In this program, we are using the ASCII codes to print alphabets from a to z. I suggest you refer to the ASCII Table to understand the ASCII values of each character in C Programming.
From the below code snippet you can see, a = 97 and z = 122
#include <stdio.h> int main() { int i; printf("\n List of Alphabets from a to z are : \n"); for(i = 97; i <= 122; i++) { printf(" %c\t", i); } return 0; }
List of 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 Alphabets from a to z using While Loop
This program for alphabets is the same as above. We just replaced the For Loop with While Loop.
#include <stdio.h> int main() { char ch = 'a'; printf("\n List of Alphabets from a to z are : \n"); while(ch <= 'z') { printf(" %c\t", ch); ch++; } return 0; }
List of 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
C Program to display Alphabets in a Given Range
This program allows the user to enter the starting alphabet. Next, the program will print the list of all alphabets between Starting_Char and z.
#include <stdio.h> int main() { char ch, Starting_Char; printf("\n Please Enter the Starting Alphabet : "); scanf("%c", &Starting_Char); printf("\n List of Alphabets from %c to z are : \n", Starting_Char); for(ch = Starting_Char; ch <= 'z'; ch++) { printf(" %c\t", ch); } return 0; }
Please Enter the Starting Alphabet : g
List of Alphabets from g to z are :
g h i j k l m n o p q r s t u v w x y z