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 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; }
---List of Lowercase Alphabets between a and z are---
a b c d e f g h i j k l m n o p q r s t u v w x y z
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; }
---List of Lowercase Alphabets between a and z are---
a b c d e f g h i j k l m n o p q r s t u v w x y z
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; }
Please Enter the Starting Lowercase Alphabet = j
---List of Lowercase between j and z are---
j k l m n o p q r s t u v w x y z
This 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; }
Please Enter the Starting Lowercase Alphabet = f
Please Enter the Starting Lowercase Alphabet = v
---List of Lowercase between f and v are---
f g h i j k l m n o p q r s t u v