Program to identify if the character is an alphabet or not

Program to identify if the character is an alphabet or not

10 May 2023

10 May 2023

Write a program to identify if the character is an alphabet or not




Description about the Program to identify if the character is an alphabet or not

Take an input character from user and check whether it is an alphabet or not.

Input

A

Output

Alphabet

Input

7

Output

Not an alphabet


C Program to identify if the character is an alphabet or not

C program using built-in function:

#include <stdio.h>

#include <ctype.h>

int main()

{

    char c;

    printf("Enter a character: ");

    scanf("%c",&c);

    if(isalpha(c))

    printf("Alphabet");

    else

    printf("not alphabet");

    return 0;

}

C Program using without built-in function:

#include <stdio.h>

int main()

{

    char c;

    printf("Enter a character: ");

    scanf("%c",&c);

    if( (c>='a' && c<='z') || (c>='A' && c<='Z'))

    printf("Alphabet");

    else

    printf("Not an alphabet");

    return 0;

}


C++ Program to identify if the character is an alphabet or not

#include <iostream>

using namespace std;

int main()

{

    char c;

    cout<<"Enter a character: ";

    cin>>c;

    if( (c>='a' && c<='z') || (c>='A' && c<='Z'))

    cout<<"Alphabet";

    else

    cout<<"Not an alphabet";

    return 0;

}


Java Program to identify if the character is an alphabet or not

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

char c;

        Scanner sc = new Scanner(System.in);

        System.out.print("Enter a Character : "); 

        c = sc.next().charAt(0);

        if((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))

System.out.println("Alphabet");

else

System.out.println("Not an alphabet");

}

}


Python Program to identify if the character is an alphabet or not

c=input() 

if('A'<=c<='Z' or 'a'<=c<='z'):

    print('Alphabet')

else:

    print('Not an alphabet')



Related Articles

Ask Us Anything !