C++ Program to determine the type of character and its ASCII value [DEVCPP/GCC]

ASCII VALUES

The ASCII values of Digits and Alphabets are in a particular sequence i.e.

Digits(0-9)                                =  48 to 57
Uppercase Alphabets(A-Z)      =  65 to 90
Lowercase Alphabets(a-z)       =  97 to 122

PROGRAM

//Program to determine the type of character and its ASCII value

#include <iostream>

using namespace std;

int main()
{
int n;
char ch;

cout<<"ENTER CHARACTER: ";
cin>>ch;

n=(int)ch;               //Type Casting into Integer

if( n>=48 && n<=57 )
{
cout<<ch<<" IS A DIGIT\n";
}
else if( n>=65 && n<=90 )
{
cout<<ch<<" IS A UPPERCASE ALPHABET\n";
}
else if( n>=97 && n<=122 )
{
cout<<ch<<" IS A LOWERCASE ALPHABET\n";
}

cout<<"ASCII VALUE: "<<n;
return 0;
}

OUTPUT


Share this

Related Posts

FIND US ON FACEBOOK!