How to write a C++ Program to Print Alphabets from A to Z | Virtual Study Solutions

Adsetra Ads

 

Write a C++ Program to Print Alphabets from A to Z

Dear Students, Today in C++ Programming Tutorial we will learn How to write C++ program to Print Alphabets from A to Z using do while loop. It is a Simple c++ program which simply start the ASCII code from capital which is 65 and keep increment the ASCII code to Z. To do this a char variable is being used and initialized it form 'A' then in while loop condition it checks till character 'Z'.

Write a C++ Program to Print Alphabets from A to Z
Write a C++ Program to Print Alphabets from A to Z
Recommended : DevC++ Installation and Usage Complete Guidelines

In this Program we will use do while loop to to Print Alphabets from A to Z. We will start the ASCII code from capital which is 65 and keep increment the ASCII code to Z. To do this a char variable is being used and initialized it form 'A' then in while loop condition it checks till character 'Z'

C++ PROGRAM CODE:


//this C++ program will print alphabets from A-Z.

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{                                //working of program
    int character=0;            //initializing variable of type int from zero to remove garbage value
    char ch='A';                //initializing character type variable from first letter 'A'
    do                         //loop begins and steps 1-5 repeat till ch=Z
    {
         character=int(ch);   //1)character=int(A) =changes value of A to ascii code of type int so
                              // character=65
         cout<<ch<<" ";     //2)print ch=A
         character++;        //3)character=66
         ch=char(character); //4)ch=char(66)=changes value of 66 to alphabet
                            // ch=B
    }
    while(ch<='Z');         //5)check if B<=Z
    getch();
}

Sample Output of a C++ Program to Print Alphabets

Sample Output of a C++ Program to Print Alphabets from A to Z
Sample Output of a C++ Program to Print Alphabets from A to Z

Have a Look on More C++ Example Programs:

If you liked this C++ Tutorial Please Share with Your friends. Thank You

Post a Comment

 

Top