Check whether a given Character is Upper case, Lower case, Number or Special Character

Problem statement:- Program to Check whether a given Character is Upper case, Lower case, Number, or Special Character.

Data requirement:-

   Input Data:- ch

  Output Data:-
string output

Program in C

Here is the source code of the C Program to Check whether a given Character is an Upper case, Lower case, Number, or Special Character.

Code:

#include<stdio.h>
int main()
{
    char ch;
    printf("Enter a character:");
    scanf("%c",&ch);
    if(ch>='a' && ch<='z')
        printf("The character is lower case");
     else if(ch>='A' && ch<='Z')
        printf("The character is upper case");
      else if(ch>='0' && ch<='9')
        printf("The character is number");
      else
        printf("It is a special character");

}

Input/Output:
Enter a character:%
It is a special character

Program in C++

Here is the source code of the C++ Program to Check whether a given Character is an Upper case, Lower case, Number, or Special Character.

Code:

#include<iostream>
using namespace std;
int main()
{
    char ch;
    cout<<"Enter a character:";
    cin>>ch;
    if(ch>='a' && ch<='z')
        cout<<"The character is lower case";
     else if(ch>='A' && ch<='Z')
        cout<<"The character is upper case";
      else if(ch>='0' && ch<='9')
        cout<<"The character is number";
      else
        cout<<"It is a special character";

}

Input/Output:
Enter a character:S
The character is upper case

Program in Java

Here is the source code of the Java Program to Check whether a given Character is an Upper case, Lower case, Number, or Special Character.

Code:

import java.util.Scanner;
public class CheckCharacter {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
char ch;
    System.out.println("Enter a character:");
    ch=cs.next().charAt(0);
    if(ch>='a' && ch<='z')
        System.out.println("The character is lower case");
     else if(ch>='A' && ch<='Z')
        System.out.println("The character is upper case");
      else if(ch>='0' && ch<='9')
        System.out.println("The character is number");
      else
        System.out.println("It is a special character");
cs.close();
}
}

Input/Output:
Enter a character:
g
The character is lower case

Program in Python

Here is the source code of the Python Program to Check whether a given Character is an Upper case, Lower case, Number, or Special Character.

Code:

ch=input("Enter a character:")
if(ch>='a' and ch<='z'):
        print("The character is lower case")
elif(ch>='A' and ch<='Z'):
        print("The character is upper case")
elif(ch>='0' and ch<='9'):
        print("The character is number")
else:
print("It is a special character") 

Input/Output:
Enter a character:5
The character is number

C/C++/Java/Python Practice Question





Post a Comment

0 Comments