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
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
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