Thursday, 1 February 2018

Hacker Rank For Loop Problem

Hacker Rank Problem


Input Format
You will be given two positive integers,  and  (), separated by a newline.
Output Format
For each integer  in the interval  :
  • If , then print the English representation of it in lowercase. That is "one" for , "two" for , and so on.
  • Else if  and it is an even number, then print "even".
  • Else if  and it is an odd number, then print "odd".
Note: 
Sample Input
8
11
Sample Output
eight
nine
even
odd

Hacker Rank Problem Solution

#include <iostream> #include <cstdio> using namespace std; // Sumit Kumar int main() { string str[] = {"","one","two","three","four","five","six","seven","eight","nine"}; int a,b; cin >> a >> b; for(int i = a; i <= b; i++){ if(i <= 9)cout << str[i] << endl; else{ if(!(i%2))cout << "even" << endl; else cout << "odd" << endl; } } return 0; }
}

2 comments:

  1. only three test cases are pass bro

    ReplyDelete
  2. int main()
    {
    string str[] = { "","one","two","three","four","five","six","seven","eight","nine" };
    int a, b;
    cin>>a >> b;
    for (int i = a; i <= b; i++) {
    if (1 >= i || i <= 9) {
    cout< 9) {
    if (i % 2 == 0) {
    printf("even\n");
    }
    else {
    cout << "odd\n";
    }
    }

    }
    return 0;
    }

    ReplyDelete

Featured post

Freecharge Recharge Hack Trick 100% Cashback