Showing posts with label std. Show all posts
Showing posts with label std. Show all posts

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;
}

Convert Centigrade to Fahrenheit

Q. 104. Program to convert Centigrade into Fahrenheit.

Note: The average body temperature is 98.60F or 370C and formula is:
         F = 9/5 * C + 32




Copy Code:

#include <iostream>
using namespace std;

int main()
{
  float c, f;
  cout << "Enter a value in Centigrade : ";
  cin >> c;
  f = ((9.0/5.0) * c) + 32;
  cout << c <<" Centigrade = " << f << " Fahrenheit";
  return 0;
}