C++ Program to print all alphabets

In this program, you will learn how to use the C++ programming language to print all the alphabets from a to z, in lower case. We can use a while loop and for loop to accomplished this goal.

More like this

C++ program to print all alphabets using a for loop

Below is the program to print all alphabets in C++ using the for loop. It loops through all from a to z, then prints the variable alphabet to the console.

#include<iostream>
using namespace std;

int main()
{
    cout << "\n---Program to print all alphabets---\n";
    
    for(char alphabets = 'a'; alphabets <= 'z'; alphabets++)
    {
        cout << alphabets << " ";
    }
    
    return 0;
}

Result

---Program to print all alphabets---
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 all alphabets using while loop

Another way to print all alphabets in C++ is to use a while loop method:

#include<iostream>
using namespace std;

int main()
{
    cout << "\n---Program to print all alphabets---\n";
    
    char alphabets='a';
    
        while(alphabets <= 'z')
    {
        cout << alphabets << " ";
        alphabets++;
    }
    
    return 0;
}

Result

---Program to print all alphabets---
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

Happy coding!

 

 

 

 

 

 

 

 

Leave a Reply

Your email address will not be published.