John wants to check if a number is even or odd. Which control structure should he use to make the decision?
- For Loop
- If-Else Statement
- Switch Statement
- While Loop
John should use an If-Else statement to check if a number is even or odd. The If-Else statement evaluates a condition and executes different code blocks based on whether the condition is true or false. In this case, John can use the modulus operator (%) to check if the number divided by 2 leaves a remainder of 0 (even) or not (odd).
Loading...
Related Quiz
- Which of the following containers in the Standard Template Library (STL) allows duplicate elements and keeps them in sorted order?
- Using too many inline functions can lead to ______ bloat.
- In C++, the conditional operator ______ is a ternary operator.
- How does the performance of a switch-case statement compare to if-else if-else chains, especially when dealing with a large number of conditions?
- A for loop that doesn’t specify the initialization, condition, and increment is known as a _______ loop.