Write a C++ Program to Print Alphabets from a to z with an example. Here, for loop (for(char lwalpCh = ‘a’; lwalpCh <= ‘z’; lwalpCh++) ) iterate characters from a to z. Within the loop, cout << lwalpCh << ” “; statement prints the characters from a to z.
#include<iostream>
using namespace std;
int main()
{
cout << "\n---List of Lowercase Alphabets between a and z are---\n";
for(char lwalpCh = 'a'; lwalpCh <= 'z'; lwalpCh++)
{
cout << lwalpCh << " ";
}
return 0;
}
In this C++ code, instead of iterating between a and z, this for loop (for(lwalpCh = 97; lwalpCh <= 122; lwalpCh++)) iterates between ASCII Values of a and z.
#include<iostream>
using namespace std;
int main()
{
char lwalpCh;
cout << "\n---List of Lowercase Alphabets between a and z are---\n";
for(lwalpCh = 97; lwalpCh <= 122; lwalpCh++)
{
cout << lwalpCh << " ";
}
return 0;
}
C++ Program to Print Alphabets from a to z using a While Loop
#include<iostream>
using namespace std;
int main()
{
char lwalpCh = 'a';
cout << "\n---List of Lowercase Alphabets between a and z are---\n";
while(lwalpCh <= 'z')
{
cout << lwalpCh << " ";
lwalpCh++;
}
return 0;
}
This C++ program to return Alphabets from a to z code allows the user to enter the starting lowercase alphabet. Next, it prints lowercase alphabets from startLwAlp to z.
#include<iostream>
using namespace std;
int main()
{
char startLwAlp;
cout << "\nPlease Enter the Starting Lowercase Alphabet = ";
cin >> startLwAlp;
cout << "\n---List of Lowercase between " << startLwAlp << " and z are---\n";
for(char lwalpCh = startLwAlp; lwalpCh <= 'z'; lwalpCh++)
{
cout << lwalpCh << " ";
}
return 0;
}
This C++ code to return Alphabets from a to z allows the user to enter the starting and ending lowercase alphabet. Next, it prints lowercase alphabets from startLwAlp to endLwAlp.
#include<iostream>
using namespace std;
int main()
{
char startLwAlp, endLwAlp;
cout << "\nPlease Enter the Starting Lowercase Alphabet = ";
cin >> startLwAlp;
cout << "\nPlease Enter the Starting Lowercase Alphabet = ";
cin >> endLwAlp;
cout << "\n---List of Lowercase between " << startLwAlp << " and " << endLwAlp << " are---\n";
for(char lwalpCh = startLwAlp; lwalpCh <= endLwAlp; lwalpCh++)
{
cout << lwalpCh << " ";
}
return 0;
}