In this post, we will learn how to display characters from A to Z using C Programming language.
So, without further ado, let’s begin the tutorial.
C Program To Display Characters from A to Z Using Loops
// C Program To Display Characters From A to Z Using Loops #include <stdio.h> int main(){ char c; // logic for (c = 'A'; c <= 'Z'; ++c){ printf("%c \n", 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
How Does This Program Work ?
char c;
In this example, we have declared a character data type variable named as c.
// logic
for (c = 'A'; c <= 'Z'; ++c){
printf("%c \n", c);
}
Then, for loop is used to print all the characters from A to Z.
Some of the used terms are as follow:
#include <stdio.h> – In the first line we have used #include, it is a preprocessor command that tells the compiler to include the contents of the stdio.h(standard input and output) file in the program.
The stdio.h is a file which contains input and output functions like scanf() and printf() to take input and display output respectively.
Int main() – Here main() is the function name and int is the return type of this function. The Execution of any Programming written in C language begins with main() function.
for loop – A loop is used for initializing a block of statements repeatedly until a given condition returns false.
printf() – printf() function is used to display and print the string under the quotation to the screen.
// – Used for Commenting in C.
C Program To Display Alphabets Using While Loop
// C Program To Display Characters From A to Z Using while Loop #include <stdio.h> int main(){ char c = 'A'; // logic while (c <= 'Z') { printf("%c \n", c); c++; } return 0; }
while Loop – In the while loop, the statements inside the body of the while loop keeps executing until it is evaluated to False.
C Program To Display Characters from A to Z Using ASCII Codes
// C Program To Display Characters from A to Z Using ASCII Codes #include <stdio.h> int main(){ int i; printf("List of all Alphabets from A to Z are:- \n"); // logic for (i = 65; i <= 90; i++){ printf("%c \n", i); } return 0; }
C Program To Print Lowercase/Uppercase Alphabets
// C Program To Print Lowercase/Uppercase Alphabets #include <stdio.h> int main(){ char c; // Asking for Input printf("Enter U or u to display Uppercase Alphabets:\n"); printf("Enter L or l to display Lowercase Alphabets:\n"); scanf("%c", &c); // logic if (c == 'U' || c == 'u'){ for (c = 'A'; c <= 'Z'; ++c){ printf("%c \n", c); } } else if (c == 'L' || c == 'l'){ for (c = 'a'; c <= 'z'; ++c){ printf("%c \n", c); } } else { printf("Invalid Character"); } return 0; }
Output 1
Enter U or u to display Uppercase Alphabets:
Enter L or l to display Lowercase Alphabets:
U
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
Output 2
Enter U or u to display Uppercase Alphabets:
Enter L or 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
Conclusion
I hope after going through this post, you understand how to display characters from a to z using C Programming language.
If you have any doubt regarding the topic, feel free to contact us in the Comment Section. We will be delighted to help you.