Write a C++ Program to Print Alphabets between A and Z with an example. Here, for loop iterator (for(char alpCh = ‘A’; alpCh <= ‘Z’; alpCh++)) iterate characters from A to Z. Within the for loop, cout << alpCh << ” “; statement prints the alphabets between A and Z.
#include<iostream>
using namespace std;
int main()
{
cout << "\n---List of Alphabets between A and Z are---\n";
for(char alpCh = 'A'; alpCh <= 'Z'; alpCh++)
{
cout << alpCh << " ";
}
return 0;
}
In this C++ example, instead of iterating from A to Z, this for loop (for(alpCh = 65; alpCh <= 90; alpCh++)) iterates between ASCII Values of A (65) and Z (90).
#include<iostream>
using namespace std;
int main()
{
char alpCh;
cout << "\n---List of Alphabets between A and Z are---\n";
for(alpCh = 65; alpCh <= 90; alpCh++)
{
cout << alpCh << " ";
}
return 0;
}
C++ Program to Print Alphabets between A and Z using While Loop
#include<iostream>
using namespace std;
int main()
{
char alpCh = 'A';
cout << "\n---List of Alphabets between A and Z are---\n";
while(alpCh <= 'Z')
{
cout << alpCh << " ";
alpCh++;
}
return 0;
}
This C++ program to return Alphabets between A and Z code allows the user to enter the starting uppercase alphabet. Next, it prints uppercase alphabets from startAlp to A.
#include<iostream>
using namespace std;
int main()
{
char alpCh, startAlp;
cout << "\nPlease Enter the Starting Uppercase Alphabet = ";
cin >> startAlp;
cout << "\n---List of Alphabets between " << startAlp << " and Z are---\n";
for(alpCh = startAlp; alpCh <= 'Z'; alpCh++)
{
cout << alpCh << " ";
}
return 0;
}
This C++ example to return Alphabets between A and Z allows the user to enter the start and end uppercase alphabet. Next, it prints uppercase alphabets from startAlp to endAlp.
#include<iostream>
using namespace std;
int main()
{
char alpCh, startAlp, endAlp;
cout << "\nPlease Enter the Starting Uppercase Alphabet = ";
cin >> startAlp;
cout << "\nPlease Enter the Ending Uppercase Alphabet = ";
cin >> endAlp;
cout << "\n---List of Alphabets between " << startAlp << " and " << endAlp << " are---\n";
for(alpCh = startAlp; alpCh <= endAlp; alpCh++)
{
cout << alpCh << " ";
}
return 0;
}