Last Updated: 3 Feb, 2021

Find Character Case

Easy
Asked in company
Amazon

Problem statement

Write a program that takes a character as input and prints either 1, 0, or -1 according to the following rules.

1, if the character is an uppercase alphabet (A - Z)
0, if the character is a lowercase alphabet (a - z)
-1, if the character is not an alphabet
Constraints :
Input can be any character.
Input format :
The only line of input contains a single character.
Output format :
The only line of output prints eith1, 0 or -1(as applicable).

Approaches

01 Approach

Take an input of a character in a variable ch.

 

if ch ≥ A && ch ≤ Z , print 1

 

else if  ch ≥ a && ch ≤ z , print 0

 

else print -1