Alphabet

C++ Program for print all Alphabet between given range using loops

C++ Program for print all Alphabets between given range using loops

In this article, we will discuss the concept of C++ Program for print all Alphabets between given range using loops

In this post, we are going to learn how to display all the upper case(A to Z) and lower case (a to z) Alphabets between given range using loops on C++ programming language

 

Display Alphabets

Program to display all Alphabet between the given range

Code to print all Alphabet using for loop

The program displays all the upper case and lower case alphabet letters between given range using for loop in C++ language

Program 1

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
    char i,ch1,ch2;
    cout<<"Enter the two Alphabet of the range: "<<endl;;
    cin>>ch1>>ch2;

    for(i=ch1; i<=ch2; i++){
     cout<<" "<<i;

//display uppercase or lower case Alphabets with space
}
getch();
    return 0;
}

When the above code is executed, it produces the following result

Case 1

Enter the two Alphabet:
j
t
Alphabet letters between j and t:
j k l m n o p q r s t


Case 2

Enter the two Alphabet:
C
K
Alphabet letters between  C and K:
C D E F G H I J K


In the above program, we are using a for loop, this is used to print upper case Alphabet letters or lower case Alphabet letters between the given range

Approach

  • In the above program, the user is asked to enter two Alphabet and entered Alphabet is stored in character variable ch1,ch2;
  • In this for loop, it is initialized by i=ch1 and checks the condition of (i<=ch2);
  • If the test expression is true, the program is printed the Alphabets letters between given Alphabets
  • If the test expression is false, the loop is terminated

 

Code to print all Alphabet using while loop

The program displays all the upper case and lower case alphabet letters between given range using while loop in C++ language

Program 2

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
    char i,ch1,ch2;
    cout<<"Enter the two Alphabet: "<<endl;
    cin>>ch1>>ch2;
    cout<<"Alphabet letters between "<<ch1<<" and "<<ch2<<": "<<endl;;

    i=ch1;
    while(i<=ch2){
     cout<<" "<<i;
 i++;
//display uppercase and lower case Alphabets with space
}
getch();
    return 0;
}

When the above code is executed, it produces the following result

Case 1

Enter the two Alphabet:
l
t
Alphabet letters between l and s:
l m n o p q r s t



Case 2

Enter the two Alphabet:
D
K
Alphabet letters between  D and K:
D E F G H I J K

In the above program, we are using a while loop, this is used to print upper case Alphabet letters or lower case Alphabet letters

Approach

  • In the above program, the user is asked to enter two Alphabet and entered Alphabet is stored in character variable ch1,ch2;
  • In this while loop, it is initialized by i=ch1 and checks the condition of (i<=ch2);
  • If the test expression is true, the program is printed the Alphabets letters between given Alphabets
  • If the test expression is false, the loop is terminated

 

Code to print all Alphabet using do-while loop

The program displays all the upper case and lower case alphabet letters between given range using do-while loop in C++ language

Program 3

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
    char i,ch1,ch2;
    cout<<"Enter the two Alphabet: "<<endl;
    cin>>ch1>>ch2;
    cout<<"Alphabet letters between "<<ch1<<" and "<<ch2<<": "<<endl;;

    i=ch1;
   do{
     cout<<" "<<i;
 i++;
//display uppercase and lower case Alphabets with space
} while(i<=ch2);
getch();
    return 0;
}

When the above code is executed, it produces the following result

Case 1

Enter the two Alphabet:
m
t
Alphabet letters between m and t:
m n o p q r s t

 

Case 2

Enter the two Alphabet:
E
M
Alphabet letters between  E and M:
E F G H I J K L M

 

In the above program, we are using a do-while loop, this is used to print upper case Alphabet letters or lower case Alphabet letters

Approach

  • In the above program, the user is asked to enter two Alphabet and entered Alphabet is stored in character variable ch1,ch2;
  • In this do-while loop, it is initialized by i=ch1 and checks the condition of (i<=ch2);
  • If the test expression is true, the program is printed the Alphabets letters between given Alphabets
  • If the test expression is false, the loop is terminated

 

Suggested for you

for loop in C++ language

while loop in C++ language

do-while loop in C++ language

 

Similar post

Java program to print all upper case and lower case Alphabets

C++ program to print all upper case and lower case Alphabets

C program to print all upper case and lower case Alphabets

Java code to print all upper case and lower case Alphabets between the given range

C++ code to print all upper case and lower case Alphabets between the given range

C code to print all upper case and lower case Alphabets between the given range

 

C Program for print all Alphabet between given range using loops
Program for Display Alphabets in Java using ASCII value
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

2 months ago