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


Please Help Members By Posting Answers For Below Questions

Define stacks. Provide an example where they are useful.

679


Difference between overloaded functions and overridden functions

681


which of the following is not an secondary constant a) array b) real c) union

1374


What is rvalue?

781


What is the use of setprecision in c++?

621






What is class and structure in c++?

647


what is COPY CONSTRUCTOR and what is it used for?

712


When is the copy constructor called?

732


How do you clear a map in c++?

684


What is the full form nasa?

673


What is function declaration in c++ with example?

618


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?

697


What is basic if statement syntax?

646


Can you sort a set c++?

624


How do I use arrays in c++?

666