C++ Switch Case Statement | Practice | GeeksforGeeks

Given a number N, if the number is between 1 and 10 both inclusive then return the number in words (Lower case English Alphabets) otherwise return "not in range".
 
Example 1:
Input:
5
Output:
five
 
Example 2:
Input:
11
Output:
not in range
 
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function isInRange() which takes an integer and if the number is between 1 and 10 both inclusive then return the number in words otherwise return "not in range".
 
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)

Constraints:
1<=N<=10000
 
0
yaminishegajqd73 hours ago
 switch(N){           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 10:{               cout<<"Ten";               break;           }           default:{               cout<<"not in range";
                      break;           }                  }   }};
0
analgesik117 hours ago
switch(N)       {           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 10: cout<<"ten"; break;           default : cout<<"not in range"; break;       }
0
singh112002muskan6 days ago
class Solution{   public:   string isInRange(int N){       // code here
      switch(N)      {          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 10:              cout<<"ten";              break;          default:              cout<<"not in range";      }     
0
pranjalrasq3sa1 week ago
---------c++------------------
 
#include <iostream>
using namespace std;
 
int main()
{
  int a;
  cout << "enter a number" << endl;
  cin >> a;
  switch (a)
  {
  case 1:
    cout << "one" << endl;
    break;
   
    case 2:
    cout << "two" << endl;
    break;
 
  case 3:
    cout << "three" << endl;
    break;
 
    case 4:
    cout << "four" << endl;
    break;
  
     case 5:
      cout << "five" << endl;
      break;
 
    case 6:
    cout << "six" << endl;
    break;
   
     case 7:
    cout << "seven" << endl;
     break;
 
     case 8:
    cout << "eight" << endl;
    break;
 
     case 9:
    cout << "nine" << endl;
    break;
 
    case 10:
    cout << "ten" << endl;
    break;
 
    default:
    cout << "not in range" << endl;
   
  }
}
 
0
prashant123singh1233 weeks ago
***********NEED HELP************
 
************C++***************
 
string isInRange(int N){       // code here        string a[] = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"};       if(N>0 && N<=10){           return a[N-1];       }       else           cout<<"not in range";   }
 
for 33rd test case i.e, 47 it is giving wrong output but when I give 47 as custom input it's giving correct answer. WHY?
 
0
rumi1w8ry3 weeks ago
class Solution:   def isInRange (ob,N):       # code here        switcher = {            1 : "one",           2 : "two",           3 : "three",           4 : "four",           5 : "five",           6 : "six",           7 : "seven",           8 : "eight",           9 : "nine",           10 : "ten",           }       return switcher.get(N, "not in range")
0
adityashrivastava29032 months ago
//Program for the same output but easier and less messy.
 
#include<iostream>
 
using namespace std;
 
int main(){string a[] = {"one", "two", "three", "four", "five", "six", "seven", "eight", “nine”, “ten”};
int n;cin>>n;
 
if(n>10){
cout<<"Not in range!";
}
cout<<a[n-1];
}
0
avicode4243 months ago
class Solution{   static String isInRange(int N){       // code here       String str = "";       switch(N)       {           case 1:               str = "one";               break;           case 2:               str = "two";               break;           case 3:               str = "three";               break;           case 4:               str = "four";               break;           case 5:               str = "five";               break;           case 6:               str = "six";               break;           case 7:               str = "seven";               break;           case 8:               str = "eight";               break;           case 9:               str = "nine";               break;           case 10:               str = "ten";               break;           default:               str = "not in range";       }       return str;          }}
0
anushavennapoosa20023 months ago
// JAVA SOLUTION
class Solution{   static String isInRange(int N){       // code here
     switch(N){      case 1: return "one";
      case 2: return "two";
      case 3: return "three";
      case 4: return "four";
      case 5: return "five";
      case 6: return "six";
      case 7: return "seven";
      case 8: return "eight";
      case 9: return "nine";
      case 10: return "ten";
      default: return "not in range";  }
   }}
0
shorouqehab0763 months ago
#include<iostream>
using namespace std;int main(){   int x;   cin >> x;   switch (x) {   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 10: cout << "ten";           break;   default: cout << "not in range";   }   return 0;}
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested 
                                    against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code.
                                    On submission, your code is tested against multiple test cases consisting of all
                                        possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as
                                        the final solution code.
You can view the solutions submitted by other users from the submission tab.
Make sure you are not using ad-blockers.
Disable browser extensions.
We recommend using latest version of your browser for best experience.
Avoid using static/global variables in coding problems as your code is tested 
                                against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases in coding problems does not guarantee the 
                                correctness of code. On submission, your code is tested against multiple test cases
                                    consisting of all possible corner cases and stress constraints.