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

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.