- 0
Notifications Mark All Read
- Login
- Get Prime
Display Alphabets
C Program to print alphabets
In this section, we will learn about how to display alphabets both in uppercase and lowercase using the printf command in C using loops. Alphabets ranging from A to Z and a to z can be printed in C using for loop. Below you will find the C program to print alphabets using two methods.
Print Alphabets in C programming:
Our main aim is to display alphabets in C programming language, which can be done in two ways:-
1. Using character variables
2. Using the ASCII values of the alphabets.
The ASCII value of ‘A’ is 65 and ranges to 90 which is of ‘Z’. Similarly, the ASCII value of ‘a’ is 97 and then on moving forward ranges till 122 which is of ‘z’.
We can print the alphabets using the character variables with the help of “%c” which represents a character.
Example 1:
#include<stdio.h> 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
Example 2:
#include<stdio.h> 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
Example 3:
#include<stdio.h> int main() { int i; printf("Alphabets from (A-Z) are:\n"); for (i = 65; i <= 90; i++) { printf("%c ", i); } printf("\nAlphabets from (a-z) are:\n"); for (i = 97; i <= 122; i++){ printf("%c ", i); } return 0; }
Output:
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 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
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment