Check whether the given character is an alphabet or not.

Program to check whether the given character is an alphabet or not is discussed here. The ASCII values of lower case alphabets are from  65 to 90 and the ASCII values of upper case alphabets are from 97 to 122. A character is obtained as input from the user. If its ASCII value lies in the above-mentioned range, it can be displayed as an alphabet.

C program to check whether the character is an alphabet or not

// C program to check whether the character is an alphabet or not

#include <stdio.h>
int main()
{
char ch;
printf(“Enter a character: “);
scanf(” %c”,&ch);
printf(“\n”);
if( (ch >= ‘a’ && ch <= ‘z’) || ( ch >= ‘A’ && ch <=’Z’))
printf(“%c is an alphabet\n”,ch);
else
printf(“%c is not an alphabet\n”,ch);

return 0;
}

// C++ program to check whether the character is an alphabet or not

#include <iostream>
using namespace std;

int main()
{
char ch;
cout << “Enter a character: “;
cin >> ch;
cout << endl;
if( (ch >= ‘a’ && ch <= ‘z’) || ( ch >= ‘A’ && ch <=’Z’))
cout << ch <<” is an alphabet ” << endl;
else
cout << ch <<” is not an alphabet ” << endl;
return 0;
}

// Java program to check whether the character is an alphabet or not

import java.util.*;
public class Main
{
public static void main(String[] args)
{
char ch;
System.out.print(“Enter a character: “);
Scanner sc = new Scanner(System.in);
ch = sc.next().charAt(0);
System.out.println();
if( (ch >= ‘a’ && ch <= ‘z’) || ( ch >= ‘A’ && ch <=’Z’))
System.out.println(ch + ” is an alphabet”);
else
System.out.println(ch + ” is not an alphabet”);
}
}

 

# Python program to check whether the character is an alphabet or not

ch = input(“Enter any character: “);

if((ch>=’a’ and ch<=’z’) or (ch>=’A’ and ch<=’Z’)):
    print(ch,end = ” “)
    print(“is an alphabet”)
else:
    print(ch,end = ” “)
    print(“is not an alphabet”)

C program to check whether the character is an alphabet or not using ASCII values

// C program to check whether the character is an alphabet or not using ASCII values

#include <stdio.h>

int main()
{
char ch;
printf(“Enter any character: “);
scanf(“%c”, &ch);
if((ch >= 97 && ch <= 122) || (ch >= 65 && ch <= 90))
{
printf(“%c is an alphabet\n”,ch);
}
else
{
printf(“%c is not an alphabet\n”,ch);
}

return 0;
}

// C++ program to check whether the character is an alphabet or not using ASCII values

#include <iostream>
using namespace std;

int main()
{
char ch;
cout << “Enter a character: “;
cin >> ch;
cout << endl;
if( (ch >= 97 && ch <= 122) || ( ch >= 65 && ch <= 90))
cout << ch <<” is an alphabet ” << endl;
else
cout << ch <<” is not an alphabet ” << endl;
return 0;
}

// Java program to check if the character is an alphabet or not using ASCII values

import java.util.*;
public class Main
{
public static void main(String[] args)
{
char ch;
System.out.print(“Enter a character: “);
Scanner sc = new Scanner(System.in);
ch = sc.next().charAt(0);
System.out.println();
if( (ch >= 97 && ch <= 122) || ( ch >= 65 && ch <=90))
System.out.println(ch + ” is an alphabet”);
else
System.out.println(ch + ” is not an alphabet”);
}
}

# Python program to check if the character is an alphabet or not using ASCII value

ch = input(“Enter any character: “);

if((ord(ch)>=97 and ord(ch)<=122) or (ord(ch)>=65 and ord(ch)<=90)):
print(ch,end = ” “)
print(“is an alphabet”)
else:
print(ch,end = ” “)
print(“is not an alphabet”)

character is an alphabet or not

character is an alphabet or not