Alphabets

Check whether a character is upper or lower case or not in C|5 ways

Check whether a character is upper or lower case or not in C

In this article, we will discuss the concept of Check whether a character is upper or lower case or not in C language

In this post, we are going to learn how to write a program to  check whether given character is Upper case or lower case or not using if else in C language

Code to find given character is Upper or Lower or not

Code to find given character Upper or Lower or not, using if statements

In this code, we are going to learn how to check  the given  character is Upper case or lower case or not using if else statements in C language

Program 1

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

int main()
{
    char ch;
    //input character from user
    printf("Input any character: ");
    scanf("%c",&ch);
    if(ch >='A' && ch<= 'Z')
    {//check if the given Alphabets is upper case
        printf("'%c' is an Upper case Alphabet",ch);
    }
    else if(ch >='a' && ch<= 'z')
    {//check if the given Alphabets is lower case
        printf("'%c' is a Lower case Alphabet",ch);
    }
    else{
        printf("'%c' is not an Alphabet",ch);
    }//Display, if the character is not an English alphabet
    getch();
    return 0;
}

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

Case 1

Input any character: A
'A' is an Upper case Alphabet

Case 2

Input any character: s
's' is a Lower case Alphabet

Case 3

Input any character: $
'$' is not an Alphabet

 

Code to find given character Upper or Lower or not, using Ascii

In this code, we are going to learn how to check  the given  character is Upper case or lower case or not using Ascii value in C language

Program 2

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

int main()
{
    char ch;
    //input character from user
    printf("Input any character: ");
    scanf("%c",&ch);
    if(ch >=65 && ch<= 90)
    {//check if the given Alphabets is upper case
        printf("'%c' is an Upper case Alphabet",ch);
    }
    else if(ch >=97 && ch<= 122)
    {//check if the given Alphabets is lower case
        printf("'%c' is a Lower case Alphabet",ch);
    }
    else{
        printf("'%c' is not an Alphabet",ch);
    }//Display, if the character is not an English alphabet
    getch();
    return 0;
}

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

Case 1

Input any character: Y
'Y' is an Upper case Alphabet

Case 2

Input any character: u
'u' is a Lower case Alphabet

 

Case 3

Input any character: $
'$' is not an Alphabet

 

Code to find given character Upper or Lower or not, using library functions

In this code, we are going to learn how to check  the given  character is Upper case or lower case or not using predefined library function in C language

Program 3

#include <stdio.h>
#include <ctype.h>

int main()
{
    char ch;
    //input character from user
    printf("Input any character: ");
    scanf("%c",&ch);
    if(isupper(ch))
    {//check if the given Alphabets is upper case
        printf("'%c' is an Upper case Alphabet",ch);
    }
    else if(islower(ch))
    {//check if the given Alphabets is lower case
        printf("'%c' is a Lower case Alphabet",ch);
    }
    else{
        printf("'%c' is not an Alphabet",ch);
    }//Display, if the character is not an English alphabet
    getch();
    return 0;
}

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

Case 1

Input any character: D
'D' is an Upper case Alphabet

Case 2

Input any character: j
'j' is a Lower case Alphabet

Case 3

Input any character: *
'*' is not an Alphabet

 

Code to find given character Upper or Lower or not, using function

In this code, we are going to learn how to check  the given  character is Upper case or lower case or not using user-defined function in C language

Program 3

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

void Ulcase(char ch);
//function prototype
int main()
{
    char ch;
    //character declaration
    //input character from user
    printf("Input any character: ");
    scanf("%c",&ch);
    Ulcase(ch);
    //Caling the function
    return 0;
}

void Ulcase(char ch){//function definition
if(ch >=65 && ch<= 90)
    {//check if the given Alphabets is upper case
        printf("'%c' is an Upper case Alphabet",ch);
    }
    else if(ch >=97 && ch<= 122)
    {//check if the given Alphabets is lower case
        printf("'%c' is a Lower case Alphabet",ch);
    }
    else{
        printf("'%c' is not an Alphabet",ch);
    }//Display, if the character is not an English alphabet
    getch();

}

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

Case 1

Input any character: K
'K' is an Upper case Alphabet

Case 2

Input any character: i
'i' is a Lower case Alphabet

Case 3

Input any character: %
'%' is not an Alphabet

 

Code to find given character Upper or Lower or not, using pointer

In this code, we are going to learn how to check  the given  character is Upper case or lower case or not using pre-defined function with pointer in C language

Program 5

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

void Ulcase(char *ch);
//function prototype with pointer argument
int main()
{
    char ch;
    //character declaration
    //input character from user
    printf("Input any character: ");
    scanf("%c",&ch);
    Ulcase(&ch);
    //Calling the function
    return 0;
}

void Ulcase(char *ch){//function definition
if(*ch >=65 && *ch<= 90)
    {//check if the given Alphabets is upper case
        printf("Upper case Alphabet");
    }
    else if(*ch >=97 && *ch<= 122)
    {//check if the given Alphabets is lower case
        printf("Lower case Alphabet");
    }
    else{
        printf("it is not an Alphabet");
    }//Display, if the character is not an English alphabet
    getch();

}


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

Case 1

Input any character: D
Upper case Alphabet

Case 2

Input any character: n
Lower case Alphabet

Case 3

Input any character: %
it is not an Alphabet

 

Suggested post

if else in C language

Nested if in C language

Operator in C language

Function 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.