-->





Print alphabets from a to z c++ program do while

C++ simple program which displays alphabets from A to Z using do while loop. This program 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'.


//this 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();
}

program output
print alphabets from z to z c++ code

Try this code to print lower case alphabets from a to z. Hint ASCII code of  'a' is 97.

Find more example here: c++ programming examples and solutions

0 comments:

Post a Comment