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

05 January 2023

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




Description

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 

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

#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

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

c=input() 

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

    print('Alphabet')

else:

    print('Not an alphabet')


Related Articles

Ask Us Anything !