Alphabets

C++ program to check whether a character is an Alphabets or Not

C++ program to check whether a character is an Alphabets or Not

In this article, we will discuss the concept of C++ program to check whether a character is an Alphabets or Not

In this post, we are going to learn how to write a program to  check whether given character is English alphabet or not  using  various ways in C++ language

Code to check character is Alphabet or Not

Code to check the character is Alphabet or Not using if-else

In this code, we are going to learn how to check  the given character is  English alphabet or not using if- else statements in C++ language

Program 1

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    char ch;//declare a character variable
//Ask to enter the character from user
    cout<<"enter a character as you wish\n";
    //Storing the entered character in variable ch
    cin>>ch;
    if((ch>='A' && ch<='Z')||(ch>='a' && ch<='z')){
cout<< ch<<" is an Alphabet: "<< endl;
// If the character  is an alphabet, it displays
}
else
{
cout<< ch<<" is not an Alphabet: "<< endl;
}// If the character  is not an alphabet, it displays
getch();
    return 0;
}

When the above code is executed, it produces the following result

Case 1

Enter a character as you wish
N
N is an Alphabets

Case 2

Enter a character as you wish
d
d is an Alphabets

Case 3

Enter a character as you wish
@
@ is not an Alphabets

 

Code to check the character is Alphabet or Not using Ascii value

In this code, we are going to learn how to check  the given character is  English alphabet or not using Ascii value in C++ language

Program 2

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    char ch;//declare a character variable
//Ask to enter the character from user
    cout<<"enter a character as you wish\n";
    //Storing the entered character in variable ch
    cin>>ch;
    if((ch>=97 && ch<=122)||(ch>=65 && ch<=90)){
cout<< ch<<" is an Alphabet: "<< endl;
// If the character  is an alphabet, it displays
}
else
{
cout<< ch<<" is not an Alphabet: "<< endl;
}// If the character  is not an alphabet, it displays
getch();
    return 0;
}

When the above code is executed, it produces the following result

Case 1

Enter a character as you wish
h
h is an Alphabets

 

Case 2

Enter a character as you wish
Q
Q is an Alphabets

 

Case 3

Enter a character as you wish
+
+ is not an Alphabets

 

Code to check the character is Alphabet or Not using isalpha()

In this code, we are going to learn how to check  the given character is  English alphabet or not using isalpha() function in C++ language

Program 3

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    char ch;
    cout << "Enter a character: " << endl;
    cin>>ch;
    if(isalpha(ch)){
         cout <<ch<<" is an Alphabet" << endl;
    }
    else{
         cout <<ch<< "is not an Alphabet " << endl;
    }
    getch();
    return 0;
}

When the above code is executed, it produces the following result

Case 1

Enter a character: E
E is an Alphabet

Case 2

Enter a character: j
j is an Alphabet

Case 3

Enter a character: *
* is not an Alphabet

 

 

Suggested post

if else statements in C++

Operator in C++ language

 

 

Similar post

Java program to print all alphabets in given range

C program to print all alphabets in given range

C++ program to print all alphabets in given range

 

Java program to print all alphabets using loops

C program to print all alphabets using loops

C++ program to print all alphabets using loops

 

Java program to check whether a character is Alphabet or Not

C++ program to check whether a character is Alphabet or Not

C program to check whether a character is Alphabet or Not

Python program to check whether a character is Alphabet or Not

 

Karmehavannan

Recent Posts

Subtract two numbers using method overriding

Subtract two numbers using method overriding   Program 1

3 months ago

PHP Star triangle Pattern program

PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…

3 months ago

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

1 year ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

1 year ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

1 year ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

1 year ago

This website uses cookies.