Given the following seqment of code containing a group of
nested if instructions: y = 9; if ((x==3) || (x == 5)) y++;
else if (x == 2) y *= 2; else if (x == 4 ) y-= 7; else y =
8; Enter a segment of code (without any IF statements) that
does exectly the same thing using the switch structure.
Answer Posted / isha
y=9;
switch(x)
{
case 2:y*=2;
break;
case 3:
case 5: y++;
break;
case 4:y-=7;
break;
default:y=8;
}
Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
Define stacks. Provide an example where they are useful.
Difference between overloaded functions and overridden functions
which of the following is not an secondary constant a) array b) real c) union
What is rvalue?
What is the use of setprecision in c++?
What is class and structure in c++?
what is COPY CONSTRUCTOR and what is it used for?
When is the copy constructor called?
How do you clear a map in c++?
What is the full form nasa?
What is function declaration in c++ with example?
If a base class declares a function to be virtual, and a derived class does not use the term virtual when overriding that class, is it still virtual when inherited by a third-generation class?
What is basic if statement syntax?
Can you sort a set c++?
How do I use arrays in c++?