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 statement in C language

Program 1

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char ch;//declare a character variable
//Ask to enter the character from user
    printf("Enter a character as you wish\n");
    //Storing the entered character in variable ch
    scanf("%c",&ch);
    if((ch>='A' && ch<='Z')||(ch>='a' && ch<='z')){
printf("%c is an Alphabet: ",ch);
// If the character  is an alphabet, it displays
}
else
{
printf("%c is not an Alphabet: ",ch);
}// 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
T
T is an Alphabets

 

Case 2

Enter a character as you wish
x
x 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

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 <stdio.h>
#include <stdlib.h>

int main()
{
    char ch;//declare a character variable
//Ask to enter the character from user
    printf("enter a character as you wish\n");
    //Storing the entered character in variable ch
    scanf("%c",&ch);
    if((ch>=97 && ch<=122)||(ch>=65 && ch<=90)){
printf("%c is an Alphabet: ",ch);
// If the character  is an alphabet, it displays
}
else
{
printf("%c is not an Alphabet: ",ch);
}// 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
M
M is an Alphabets

 

Case 2

Enter a character as you wish
c
c 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() function

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 <stdio.h>
#include <stdlib.h>

int main()
{
    char c;//declare a character variable
    printf("Enter a character\n");
    scanf("%c",&c);//ask and store a character
    if(isalpha())//check the character is alphabet or not
        printf("%c is an Alphabet",c);

    else
         printf("%c is not an Alphabet",c);
    getch();
    return 0;
}

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

Case 1

Enter a character as you wish
E
E is an Alphabets

 

Case 2

Enter a character as you wish
v
v is an Alphabets

 

Case 3

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

 

Suggested post

if statement in C language

Function in C language

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

Multiply two numbers in Java using scanner| 5 different ways

Multiply two numbers in Java using scanner| 5 different ways In this article, we will…

3 months ago

5 different ways to Divide two numbers in Java using scanner

5 Different ways to Divide two numbers in Java using scanner In this article, we…

3 months ago

Learn 8 Ways to Subtract Two Numbers Using Methods in Java

Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…

4 months ago

10 ways to subtract two numbers in Java

10 ways to subtract two numbers in Java In this article, we will discuss the…

4 months ago

Java Code Examples – Multiply Two Numbers in 5 Easy Ways

Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…

4 months ago

How to Divide two numbers in Java| 5 different ways

How to Divide two numbers in Java| 5 different ways In this article, we will…

4 months ago

This website uses cookies.