Showing posts with label lower to upper. Show all posts
Showing posts with label lower to upper. Show all posts

Sunday, August 23, 2015

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;

}

Saturday, August 22, 2015

Change Case of a Word

Q. 101. C++ Program to accept a word and change the Upper case (capital) letters to Lower case (small) and Lower case letters to Upper case.



Copy Code:

#include <iostream>
using namespace std;

int main()

{
  char ch [50]; int i = 0;
  cout << "Enter a Word : ";
  cin >> ch;
  while( ch[ i ] != '\0' )
  {
     if ( ch[ i ] >= 'a'  &&  ch[i] <= 'z' )
         ch [ i ] = ch [ i ] - 32;
     else 
     if ( ch[ i ] >= 'A'  &&  ch[i] <= 'Z' )
         ch [ i ] = ch [ i ] + 32;

     ++i;
   }
  cout << "Word with Changed Case is : "<< ch;
  return 0;
}