Friday, July 21, 2017

Convert given number into word

C++ Program to convert given number (between 0 to 9) into word using switch statement.


#include<iostream>
using namespace std;

int main ()
{
 int number;

 cout << "Enter your number:";
 cin >> number;
 switch(number)
 {
  case 1 : cout << "One";
  break;
  case 2 : cout << "Two";
           break;
  case 3 : cout << "Three";
           break;
  case 4 : cout << "Four";
           break;
  case 5 : cout << "Five";
           break;
  case 6 : cout << "Six";
           break;
  case 7 : cout << "Seven";
           break;
  case 8 : cout << "Eight";
           break;
  case 9 : cout << "Nine";
           break;
  case 0 : cout << "Zero";
           break;
  default :printf("Invalid number\n" );
 }
 return 0;
}

Output of the program

Enter your number:5
Five

No comments:

Post a Comment