Sort by

recency

|

1629 Discussions

|

  • + 0 comments

    Hello there! My code isnt the most optimal, but i used my knowledge of switch case and solved this:

    int main(){
    	int a, b;
    	cin >> a >> b ;
    	for(int i=a; i<=b; i++){
    		if(i <= 9 && i >= 1){
    				switch(i){
    				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;
    				default:
    					break;
    				}
    		}else{
    			if(i%2==0){
    				cout << "even" << endl;
    			}else{
    				cout << "odd" << endl;
    			}
    		}
    	}
    	return 0;
    }
    
  • + 1 comment
    int a,b;
    char arr[11][6]={"one","two","three","four","five","six","seven","eight","nine","even","odd"};
        
    cin>>a>>b;
    
    for( int i = a; i <= b; i++){
            if(i < 10)
                cout<<arr[i-1]<<endl;
            else if(i % 2 == 0)
                cout<<arr[9]<<endl;
            else 
                cout<<arr[10]<<endl;
        }
    
  • + 0 comments

    include

    using namespace std;

    int main() {

    int a, b;
    cin >> a >> b;
    
    string num[] = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    
    for (int i = a; i <= b; i++){
        if(i >= 1 && i <= 9){
            cout << num[i - 1] << endl;
        }
        else {
            if (i % 2 == 0 && i > 9){
                cout << "even" << endl;
            }
            else {
                cout << "odd" << endl;                
            }
        }
    }
    return 0;
    

    }

  • + 0 comments

    how do I obtain multiple inputs without sstream? am i suppose to do sstream? (more than a and b)

  • + 0 comments

    Great solution here! I think using a switch statement for the numbers 1 through 9 makes it more readable. However, using a simple array for the numbers, as shown in other solutions, can make the code more concise and easier to maintain. I recently faced a similar challenge with device troubleshooting, where knowing the specific behavior of each part helped me diagnose issues faster. If you ever run into tech problems, like phone or computer issues, Doctor Mobile Profix offers reliable repair services with a quick turnaround. Thanks for sharing this!