Signup/Sign In

C Program To Display characters from A-Z using Loops

In this tutorial, we will see how to print all the English alphabets using loops. But before moving forward, if you are not familiar with the concept of loops in C, then do check the article on Loops in C. For Example,

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

There are several methods of displaying the alphabets using a loop:

Method 1: Using ASCII Codes

Method 2: Using For Loop

Method 3: Using While Loop

Method 4: Using Functions

Let us take a look at each of these methods separately.

Program 1: Print all the English Alphabets

In this method, we will use the ASCII value of each character and print the corresponding elements. We will use a for loop to iterate through each element.

Algorithm:

  1. Start

  2. Declare an integer type variable.

  3. Assign it to the ASCII value of the first English alphabets.

  4. Use this variable as the loop variable.

  5. Iterate till the last element of the English alphabet.

  6. Print the character corresponding to the ASCII value.

  7. Stop.

Below is the code for the same.

The below demonstrates how to print all the English alphabets using ASCII code and a for loop. Here, the for loop will ensure that the characters are only between A-Z when their ASCII value is provided.

//C Program to print all the english alphabets
#include <stdio.h>

int main()
{
    printf("Alphabets from A - Z are: \n");

    /* ASCII value of A=65 */
    for(int i=65; i<=90; i++)
    {
        /* When integer i is used with %c it will convert an integer 
          to a character before printing. This will take ASCII from
           i and display the character equivalent. */
        printf("%c ", i);
    }
    printf("\n");
    return 0;
}


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 2: Print all the English Alphabets

In this method, a for loop is used to print all the English alphabets. For this, a character type variable is taken as the loop variable. This loop variable is assigned with the first English alphabet and is incremented by one on every iteration.

Algorithm:

  1. Start

  2. Declare a char type variable.

  3. Initialize this variable to the first English alphabet.

  4. Use a for loop to iterate through the elements.

  5. Start printing the elements.

  6. Increment the loop variable by one after each iteration.

  7. Print the rest of the elements till the condition is reached.

  8. Stop.

Below is the code for the same.

The below demonstrates how to print all the English alphabets using a for loop. Here, the for loop will ensure that the characters are only between A-Z.

//C Program to print all the english alphabets
#include <stdio.h>
 
int main()
{
  	char ch;   //Declare a character type variable

	printf("\nList of Alphabets from A to Z are : \n");  
  	for(ch = 'A'; ch <= 'Z'; ch++)     //Using a For loop iterate through all the elements
  	{
  		printf(" %c\t", ch);	//Print the english alphabets
	}
  
  	return 0;
}


List of 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 3: Print all the English Alphabets

In this method, a while loop is used to print all the English alphabets. For this, a character type variable is taken as the loop variable. This loop variable is assigned with the first English alphabet and is incremented by one on every iteration.

Algorithm:

  1. Start

  2. Declare a char type variable.

  3. Initialize this variable to the first English alphabet.

  4. Use a while loop to iterate through the elements.

  5. Start printing the elements.

  6. Increment the loop variable by one after each iteration.

  7. Print the rest of the elements till the condition is reached.

  8. Stop.

Below is the code for the same.

The below demonstrates how to print all the English alphabets using a while loop. Here, the while loop will ensure that the characters are only between A - Z.

//C Program to print all the english alphabets
#include <stdio.h>
 
int main()
{
  	char ch = 'A';      //Declare a character variable

	printf("\n List of Alphabets from A to Z are : \n");  
  	while(ch <= 'Z')    //Using while loop iterate through all the elements
  	{
  		printf(" %c\t", ch);
		  ch++;	        //Increment the character
	}
  
  	return 0;
}


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 4: Print all the English Alphabets

In this method, we call a function and use a while loop to print all the English alphabets. For this, a character type variable is taken as the loop variable. This loop variable is assigned with the first English alphabet and is incremented by one on every iteration.

Algorithm:

  1. Start

  2. Declare a char type variable.

  3. Initialize this variable to the first English alphabet.

  4. Call a function to print all the English alphabets.

  5. Use a while loop to iterate through the elements.

  6. Start printing the elements.

  7. Increment the loop variable by one after each iteration.

  8. Print the rest of the elements till the condition is reached.

  9. Stop.

Below is the code for the same.

In the below program, we call a function that is used to print all the English alphabets. In this method, we will use a while loop to iterate through all the elements and then print all the English alphabets.

//C Program to print all the english alphabets
#include <stdio.h>
void printAlphabets(char ch);   //Function Declaration
int main()
{
    char ch='A';          //Declare a variable and initialize it to the first character of engllish alphabet
    printf("Alphabets from A - Z are: \n");
    printAlphabets(ch);   //Function Call
    return 0;
}
void printAlphabets(char ch)     //Function Definition
{
    while(ch <= 'Z')
  	{
  		printf(" %c ", ch);
		  ch++;	
	}
}


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



About the author:
I like writing content about C/C++, DBMS, Java, Docker, general How-tos, Linux, PHP, Java, Go lang, Cloud, and Web development. I have 10 years of diverse experience in software development. Founder @ Studytonight