August 2010
6 Friday
Draw a flow chart to enter a
characten from keyboard if
character is smal letter convent
to tipital or vice versa.
Answers
Answer:
Check whether the given character is in upper case, lower case or non alphabetic character
Last Updated: 23-04-2019
Given a character, the task is to check whether the given character is in upper case, lower case or non-alphabetic character
Examples:
Input: ch = 'A'
Output: A is an UpperCase character
Input: ch = 'a'
Output: a is an LowerCase character
Input: ch = '0'
Output: 0 is not an aplhabetic character
Recommended: Please try your approach on {IDE} first, before moving on to the solution.
Approach: The key to solve this problem lies in the ASCII value of a character. It is the most simple way to find out about a character. This problem is solved with the help of following detail:
Capital letter Alphabets (A-Z) lie in the range 65-91 of the ASCII value
Small letter Alphabets (a-z) lie in the range 97-122 of the ASCII value
Any other ASCII value is a non-alphabetic character.
Implementation:
C++
filter_none
edit
play_arrow
brightness_4
// C++ implementation of the above approach
#include<bits/stdc++.h>
using namespace std;
void check(char ch)
{
if (ch >= 'A' && ch <= 'Z')
cout<< ch << " is an UpperCase character\n";
else if (ch >= 'a' && ch <= 'z')
cout<< ch << " is an LowerCase character\n";
else
cout<< ch << " is not an aplhabetic character\n";
}
// Driver Code
int main()
{
char ch;
// Get the character
ch = 'A';
// Check the character
check(ch);
// Get the character
ch = 'a';
// Check the character
check(ch);
// Get the character
ch = '0';
// Check the character
check(ch);
return 0;
}
// This code is contributed by Code_Mech
C
filter_none
edit
play_arrow
brightness_4
// C implementation of the above approach
#include <stdio.h>
void check(char ch)
{
if (ch >= 'A' && ch <= 'Z')
printf("\n%c is an UpperCase character",
ch);
else if (ch >= 'a' && ch <= 'z')
printf("\n%c is an LowerCase character",
ch);
else
printf("\n%c is not an aplhabetic character",
ch);
}
// Driver Code
int main()
{
char ch;
// Get the character
ch = 'A';
// Check the character
check(ch);
// Get the character
ch = 'a';
// Check the character
check(ch);
// Get the character
ch = '0';
// Check the character
check(ch);
return 0;
}
Java
filter_none
edit
play_arrow
brightness_4
// Java implementation of the above approach
class GFG
{
static void check(char ch)
{
if (ch >= 'A' && ch <= 'Z')
System.out.println("\n" + ch +
" is an UpperCase character");
else if (ch >= 'a' && ch <= 'z')
System.out.println("\n" + ch +
" is an LowerCase character" );
else
System.out.println("\n" + ch +
" is not an aplhabetic character" );
}
// Driver Code
public static void main(String []args)
{
char ch;
// Get the character
ch = 'A';
// Check the character
check(ch);
// Get the character
ch = 'a';
// Check the character
check(ch);
// Get the character
ch = '0';
0 is not an aplhabetic character