We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. C++
  3. Introduction
  4. For Loop
  5. Discussions

For Loop

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 1427 Discussions, By:

recency

Please Login in order to post a comment

  • ptmkhanh29
    1 week ago+ 0 comments
    int main() {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT */
        int a, b;
        std::vector<std::string> words = {"zero","one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "even", "odd"};
        scanf("%d\n%d", &a, &b);
        for(int i = a; i <= b; i++){
            if(i > 9) {
                if(i%2 == 0) cout << words[10 + i%2] << endl;
                else cout << words[10 + i%2] << endl;
            } 
            else{
                cout << words[i] << endl;
            }
        }
        return 0;
    }
    
    0|
    Permalink
  • nandini16chatte1
    1 week ago+ 0 comments

    include

    include

    using namespace std;

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

    return 0;
    

    }

    0|
    Permalink
  • creeper4004
    1 week ago+ 0 comments

    It cant get better

    #include <iostream>
    #include <vector>
    
    int main()
    {
        std::vector<std::string> words = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
        int begin, end;
        std::cin >> begin >> end;
        for (int i = begin; i <= end; ++i)
        {
            if (i <= 9)
                std::cout << words[i] << std::endl;
            else
                std::cout << (i % 2 == 0 ? "even" : "odd") << std::endl;
        }
        return 0;
    }
    
    1|
    Permalink
  • gangadharghru67
    2 weeks ago+ 0 comments

    Here are the solution of For Loop in C++ Hacker Rank Solution

    0|
    Permalink
  • vedikadwivedi241
    2 weeks ago+ 0 comments

    include

    include

    using namespace std;

    int main() { // Complete the code. int a,b; cin >>a; cin >>b;

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

    }

    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy