C++ Programming

C++ – Input Character and Display Vowel or Not

Write a program that prints the ASCII code of the input character (both upper case and lower case) and displays whether the character is a vowel or not.

e.g. if ‘A’ is inputted then the output should be 65 and should display ‘vowel’.

Source Code

#include<iostream.h>
#include<conio.h>
void main()
{
    int num;
    char ascii;
    cout<<"Enter character:";
    cin>>ascii;
    cout<<"it ascii value is:"<<(int)ascii<<endl;
    if(ascii=='a'||ascii=='e'||ascii=='i'||ascii=='o'||ascii=='u'||ascii=='A'||
    ascii=='E'||ascii=='I'||ascii=='O'||ascii=='U')
    cout<<"It is vowel";
    else
      cout<<"Not Vowel";
    getch();
}

Output:

Enter a character: a
It ASCII value is: 97
It is vowel

Back to top button