Assignments » Library Function » Set1 » Solution 3

Write a program to check character entered is alphabet, digit or special character.


#include<iostream.h>
#include<conio.h>
#include<ctype.h>
#include<stdio.h>

int main()
{
	char ch;
	cout<<"Enter any character :";
	ch=getchar();
	if(isalpha(ch))
		cout<<"Alphabet";
	else if(isdigit(ch))
		cout<<"Number";
	else
		cout<<"Special Character";
	getch();
	return 0;
}

#include<iostream>
#include<cctype>
using namespace std;

int main()
{
	char ch;
	cout<<"Enter any character :";
	ch=getchar();
	if(isalpha(ch))
		cout<<"Alphabet";
	else if(isdigit(ch))
		cout<<"Number";
	else
		cout<<"Special Character";
	
	return 0;
}

SAMPLE RUN # 1

Enter any character : Z
Alphabet

SAMPLE RUN # 2

Enter any character : 9
Number

SAMPLE RUN # 3

Enter any character : $
Special Character

 

«back