C++ Program for Display Alphabets using ASCII value
C++ Program for Display Alphabets using ASCII value
In this article, we will discuss the concept of C++ Program for Display Alphabets using ASCII value
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 using ASCII value in C++ programming language
![C++ Program for Display Alphabets in Java using ASCII value](https://i0.wp.com/code4coding.com/wp-content/uploads/2020/03/asciialpha.jpg?resize=469%2C380&ssl=1)
- ASCII value of upper case Alphabets letters are between 65 – 90
- ASCII value of lower case Alphabets letters are between 97 – 122
Code for Display all upper case and lower case Alphabets Using for loop
The program displays all the upper case and lower case alphabet letters between a to z using for loop in C++ language
Program 1
#include <iostream> #include <conio.h> using namespace std; int main() { char ch;//char variable declaration //Printing upper case Alphabets cout<<"Uppercase Alphabets are: \n"; for(ch=65; ch<=90; ch++){ cout<<ch<<" "; //display uppercase Alphabets with space } cout<<"\n";//move to next line //Printing lower case Alphabets cout<<"\nLowercase Alphabets are: \n"; for(ch=97; ch<=122; ch++){ cout<<ch<<" "; //display lowercase Alphabets with space } cout<<"\n";//move to next line //printf("Hello world!\n"); getch(); return 0; }
When the above code is executed, it produces the following result
![C++ Program for Display Alphabets using ASCII value](https://i0.wp.com/code4coding.com/wp-content/uploads/2020/03/asciialpa1.jpg?resize=629%2C237&ssl=1)
In the above program, we are using two for loops, one is used to print upper case letters and another to print lower case letters
Approach
- We will declare a counter variable “ch” of the for loop and it is initialized by “65”(for print upper case) or “97” (for print lower case);
- The program checks the given condition(ch<=90 (upper case) or ch<=122(lower case) if the condition is true, alphabets will be printed
- if the condition is false – loops will be terminated
Code for print upper case and lower case Alphabets Using while loop
The program displays all the upper case and lower case alphabet letters between a to z using while loop in C++ language
Program 2
#include <iostream> #include <conio.h> using namespace std; int main() { char ch;//char variable declaration //Printing upper case Alphabets cout<<"Uppercase Alphabets are: \n"; ch=65; while( ch<=90){ cout<<ch<<" "; //display uppercase Alphabets with space ch++; } cout<<"\n";//move to next line //Printing lower case Alphabets cout<<"\nLowercase Alphabets are: \n"; ch=97; while(ch<=122){ cout<<ch<<" "; //display lowercase Alphabets with space ch++; } cout<<"\n";//move to next line //printf("Hello world!\n"); getch(); return 0; }
When the above code is executed, it produces the following result
![C++ Program for Display Alphabets using ASCII value](https://i0.wp.com/code4coding.com/wp-content/uploads/2020/03/asciialpa1.jpg?resize=590%2C222&ssl=1)
In the above program, we are using two while loops, one is used to print upper case letters and another to print lower case letters
Approach
- We will declare a counter variable “ch” of the while loop and initialize it by “65”(for print upper case) or “97” (for print lower case);
- The program checks the given condition(ch<=90 (upper case) or ch<=122(lower case) if the condition is true, alphabets will be printed
- if the condition is false – loops will be terminated
Code for Display all upper case and lower case Alphabets Using the do-while loop
The program displays all the upper case and lower case alphabet letters between using the do-while loop in C++ language
Program 3
#include <iostream> #include <conio.h> using namespace std; int main() { char ch;//char variable declaration //Printing upper case Alphabets cout<<"Uppercase Alphabets are: \n"; ch=65; do{ cout<<ch<<" "; //display uppercase Alphabets with space ch++; }while( ch<=90); cout<<"\n";//move to next line //Printing lower case Alphabets cout<<"\nLowercase Alphabets are: \n"; ch=97; do{ cout<<ch<<" "; //display lowercase Alphabets with space ch++; }while(ch<=122); cout<<"\n";//move to next line //printf("Hello world!\n"); getch(); return 0; }
When the above code is executed, it produces the following result
![C++ Program for Display Alphabets using ASCII value](https://i0.wp.com/code4coding.com/wp-content/uploads/2020/03/asciialpa1.jpg?resize=640%2C241&ssl=1)
In the above program, we are using two do-while loops, one is used to print upper case letters and another to print lower case letters
Approach
- We will declare a counter variable “ch” of the do-while loop and initialize it by “65”(for print upper case) or “97” (for print lower case);
- The program checks the given condition(ch<=90 (upper case) or ch<=122(lower case) if the condition is true, alphabets will be printed
- if the condition is false – loops will be 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
C Program for Display Alphabets in Java using ASCII value
Java Program for Display Alphabets in Java using ASCII value
C++ Program for Display Alphabets in Java using ASCII value
Python Program for Display Alphabets in Java using ASCII value