Sort by

recency

|

1651 Discussions

|

  • + 0 comments

    Now we encounter the problem based on the basics of c++ ; "we can't use datastructures or any arrays".

    so I get the code

    CODE :

    include

    include

    using namespace std;

    int main() { // Complete the code. int n,m;

    cin>>n>>m;
    // cout<<n<<m;
    for(int i=n;i<=m;i++){
        if(i==1){
            cout<<"one"<<"\n";
        }
        else if(i==2){
            cout<<"two"<<"\n";
        }
        else if(i==3){
            cout<<"three"<<"\n";
        }
        else if(i==4){
            cout<<"four"<<"\n";
        }
        else if(i==5){
            cout<<"five"<<"\n";
        }
        else if(i==6){
            cout<<"six"<<"\n";
        }
        else if(i==7){
            cout<<"seven"<<"\n";
        }
        else if(i==8){
            cout<<"eight"<<"\n";
        }
        else if(i==9){
            cout<<"nine"<<"\n";
        }
        else if(i>9){
            if(i%2 ==0){
                cout<<"even"<<"\n";
            }
            else{
                cout<<"odd"<<"\n";
            }
        }
    }
    return 0;
    

    }

    }

  • + 0 comments
    int main() {
        string words[] = {
            "one", "two", "three", "four", 
            "five", "six", "seven", "eight", 
            "nine"
        }; 
        
        int a, b; 
        cin >> a;
        cin >> b; 
        
        for (int i = a; i <= b; i++) {
            if(i >= 1 && i <= 9) {
               cout << words[i - 1] << "\n"; 
            }
            else if (i > 9) {
                if( i % 2 == 0) {
                    cout << "even \n"; 
                }
                else {
                    cout << "odd \n"; 
                }
            }
        }
        
        return 0;
    }
    
  • + 0 comments
    int main() {
        // Complete the code.
        string number_str[11]= { 
        "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "even", "odd"
    };
        
        int a = 0, b = 0, idx = 0;
                
        scanf("%d\n%d", &a, &b);
        
        for (int i=a; i <=b; i++) {
          idx = (i>0 && i<10) ? i-1 : i%2+9;
          printf("%s\n", number_str[idx].data());
        }
    
        return 0;
    }
    
  • + 0 comments

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

    return 0;
    

    }

  • + 0 comments

    Here is For loop in c++ solution - https://programmingoneonone.com/hackerrank-for-loop-solution-in-cpp.html