C Program to Display Characters from A to Z Using Loop

by | Jan 27, 2023 | C, C Programs

Home » C » C Programs » C Program to Display Characters from A to Z Using Loop

Introduction

In this program, you will learn to display all the letters of the English alphabet,

Using the ‘for’ loop, we will display the letter from A to Z on the screen.

To understand this program, you should have knowledge of the following C programming concepts:

1. C if…else statement

2. C for loop

3. while and do..while loop

The program can be made with any loop (for, while, do-while)

Program

#include<stdio.h>
int main()
{
char c;
printf("Aphabets are:\n");
for(c='A';c<='Z';c++) // loop iterate from ‘A’ to ‘Z’.
{
printf("%c ",c);
}
}

 

Output

Explanation

The above program is very simple, using for loop, and we display the characters from A to Z.

for(c=’A’;c<=’Z’;c++)

‘c’ is any character variable that will iterate from A to Z, and each iteration will be displayed on the screen.

More methods

1. To print lowercase alphabets, the ‘for’ loop statement will become

for(c=’a’;c<=’z’;c++)

2. To print all English letter alphabets, we can also use the ASCII value range of lowercase and uppercase alphabets.

For upper-case alphabets, the program will look like

#include<stdio.h>

int main()

{

int c; // ‘c’ is a int variable to store ASCII value

printf(“Aphabets are:\n”);

for(c=97; c<=122; c++)

{

printf(“%c “,c); // here the variable ‘c’ is type casted to char to print characters with respect to their ASCII value.

}

}

3. For uppercase alphabets, the for loop in the above code will be written as

for(c=65; c<=90; c++)

 

Author

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Author