Showing posts with label ASCII value. Show all posts
Showing posts with label ASCII value. Show all posts

Sunday, August 23, 2015

Check Capital, Small, Digit, Special Character from Keyboard Input


Q. 86. Program to accept a character and print if its a Capital letter, Small letter, Digit or Special Character.


Copy Code:

#include<iostream>

using namespace std;

int main()

{

  char ch ;

  cout << "Enter any character : ";

  cin >> ch;

  

  if (ch>='A'  &&  ch<='Z')

     cout << ch << " is a Capital Letter";

  else if (ch>='a'  &&  ch<='z')

     cout << ch << " is a Small Letter";

  else if (ch>='0'  &&  ch<='9')

     cout << ch << " is a Digit";

  else 

     cout << ch << " is a Special Character";

   return(0);

}

Program to change Case of an Alphabet

Q. 87. Program to accept any Alphabet and change the Case



Copy Code:

#include <iostream>

using namespace std;


int main()

{

  char ch ;

  cout << "Enter an Alphabet : "; cin >> ch;

  

  if (ch>='A'  &&  ch<='Z')

     {

       ch+=32;  // ch=ch+32

       cout << "Lower case is "<< ch;

      }

  else if (ch>='a'  &&  ch<='z')

     {

      ch-=32;  // ch=ch-32

      cout << "Upper case is "<< ch;

     }

  else 

      cout << "Not an Alphabet";

  

return 0;

}