- Practice
- C++
- Introduction
- For Loop
- Discussions

# For Loop

# For Loop

jvinniec + 0 comments Ok, this took me the better part of an hour to figure out what they are asking in this question. Basically, the idea is you are given two numbers 'a' and 'b' such that a<=b. You then need to test every number from a to b and output either the text version of the variable (if number <=9) or whether the value is even or odd (if number > 9).

So basically when the inputs are 8,11 you need to test every integer from 8 to 11, so you need to test 8,9,10,& 11. This leads to the output specified in the "Sample Output" of "eight, nine, even, odd". Hopefully this helps someone out.

Dineshs91 + 0 comments Input format and sample input are different. The question is ambiguous.

rockpile + 0 comments `int a,b; string num[10] = {"zero","one","two","three","four","five","six","seven","eight","nine"}; cin >> a >> b; for (int i = a; i <= b; ++i) { if (i > 9) { i % 2 == 0 ? cout << "even\n" : cout << "odd\n"; } else { cout << num[i] << endl; } } return 0;`

Manbear + 0 comments This challenge needs editing, because the description is very vague and can only be solved if referring to the comments section for an explanation.

JChiquin + 0 comments The ternary operator is the best!

int main() { string hour[]={"even","odd","one","two","three","four","five","six","seven","eight","nine"}; int a,b; for(cin>>a>>b;a<=b;a++) cout<<hour[a>9?a%2:a+1]<<'\n'; return 0; }

Sort 893 Discussions, By:

Please Login in order to post a comment