Quiz: Control Structures
Take this quiz to test your understanding of the different combinations of control structures.
We'll cover the following...
We have covered the selection control structures (if, if-else, and switch) and repetition or iteration control structures (while, for, and do-while).
Let’s solve some quiz questions below to revise the working of different combinations of nested control structures. In the quiz, we may have multiple correct options. So let’s start!
Question: if, switch, and for
Refer to the following code snippet to answer the quiz questions below.
For marks = 90, what grade would be displayed?
A
A-
Question: for and while
Refer to the following code snippet to answer the quiz questions below.
What will be the output of the above code if we enter -5, 7, 2, and 10 as inputs?
No output
14
Question: if and do-while
Refer to the following code snippet to answer the quiz questions below.
What will be the output of the following code if we enter -5, 1, 12, and 10 as inputs?
No output
18
2
Question: for, if and, if-else
Refer to the following code snippet to answer the quiz questions below.
Variant 1
int max,
value;
for(int i=1; i<=5; i++)
{
cin >> value;
if(i==1)
max = value;
else if(value > max)
max = value;
}
cout << max;
Variant 2
int max, value;
cin >> value;
max=value;
for(int i=2; i<=5; i++)
{
cin >> value;
if(value > max)
max = value;
}
cout << max;
Which of the code variants is more efficient?
Variant 1
Variant 2
Coding playground
If you chose a wrong answer to any of the questions above, use the editor below to run that question’s code and observe its output.
#include<iostream>
using namespace std;
int main()
{
// Test your code here.
return 0;
}