Write a C++ program to accept a character and determine whether its number, alphabet or symbol.

Q18. Write a C++ program to accept a character and determine whether its number, alphabet or symbol.

Solution:

#include<iostream.h> //standard input/output header file

#include<conio.h> //for clrscr()

 

int main()

{

char a;

 

clrscr(); //for clearing the screen

 

cout<<“\n Enter any character: “;

cin>>a;

 

a>=65&&a<=90||a>=97&&a<=122? cout<<“\n It is an alphabet.” : a>=48&&a<=57? cout<<“\n It is a number.” : cout<<“\n It is a symbol.”;

 

getch(); //holds the screen until any key is pressed

return 0; //makes main() finish

}

 

OUTPUT:

CASE 1:

Enter any character: d

 

It is a alphabet.

 

 

CASE 2:

Enter any character: 3

 

It is a number.

 

CASE 3:

Enter any character: $

 

It is a symbol.

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: