Header Ads Widget

C program to check whether a character is uppercase or lowercase alphabet

 C program to check whether a character is uppercase or lowercase alphabet

Given a character , write a program to check whether it is uppercase or lowercase .

Method 1: By using standard function ( isupper() and islower() ) .

Method 2: By Checking range i.e ( if Character is in range A to Z then uppercase ).

Method 3: By using Ascii values . (Ascii of A to Z is 65 to 90 and Ascii value of a to z is 97 to 122 )

Sample input

A 

Sample output

A is Uppercase

C program to check whether a character is uppercase or lowercase alphabet

The objective of the code is to check whether it is uppercase or lowercase alphabet .

Method 1:

#include<stdio.h>
int main()
{
char ch;
scanf("%c",&ch);
if(isupper(ch))
printf("%c is Uppercase",ch);
else if(islower(ch))
printf("%c is Lowercase",ch);
else
printf("Invalid input");
return 0;
}


Output:-

A
A is Uppercase

Method 2:

#include<stdio.h>
int main()
{
char ch;
scanf("%c",&ch);
if(ch>='A' && ch<='Z')
printf("%c is Uppercase",ch);
else if(ch>='a' && ch<='z')
printf("%c is Lowercase",ch);
else
printf("Invalid input");
return 0;
}

Output:-

A
A is Uppercase

Method 3 : (By using Ascii value)

#include<stdio.h>
int main()
{
char ch;
int a;
scanf("%c",&ch);
// converting character into
// integer i.e Ascii value
a=ch;
if(a>=65 && a<=90)
printf("%c is Uppercase",ch);
else if(a>=97 && a<=122)
printf("%c is Lowercase",ch);
else
printf("Invalid input");
return 0;
}


Output:-

A
A is Uppercase

Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-

Post a Comment

0 Comments