Using loops, write a C++ program that displays a series of alphabets in descending order from ‘Z’ to ‘A.’

cpp programming exercise with solution
cpp programming exercise with solution

By using while loop

#include <iostream>
using namespace std;

int main()
{
char alphabet = 'Z';

while(alphabet >= 'A')
{
cout<<alphabet<<" ";
alphabet--;
}
    return 0;
}

By using for loop

#include <iostream>
using namespace std;

int main()
{
char alphabet;
for (alphabet = 'Z'; alphabet >= 'A'; alphabet--)
{
cout<<alphabet<<" ";
}
return 0;
}


Modify your program in the previous part so that the program will display consonants only, no vowels.

cpp programming exercise with solution
cpp programming exercise with solution

#include <iostream>
using namespace std;

int main()
{
char alphabet;
for (alphabet = 'Z'; alphabet >= 'A'; alphabet--)
{
if (alphabet != 'A' && alphabet != 'E' && alphabet != 'I' && alphabet != 'O'
&& alphabet != 'U')
{
cout<<alphabet<<" ";
}
}
return 0;
}