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

What are dynamic type checking?

614


What is the role of copy constructor in copying of thrown objects?

596


What does 7/9*9 equal ? a) 1 b) 0.08642 c) 0

578


What is enum class in c++?

706


What is a string example?

547






How does list r; differs from list r();?

687


If all is successful, what should main return a) 0 b) 1 c) void

558


Can a function take variable length arguments, if yes, how?

565


What do you mean by function and operator overloading in c++?

611


Is c# written in c++?

518


What is general format for a prototype?

595


Reads in the size of a square from the screen; 2. Prints a hollow square of that size out of “-“, “|” and blanks on screen; 3. Prints the same hollow square onto a text file. Your program should work for squares of all side sizes between 1 and 20. --- │ │ │ │ │ │ ---

1643


What is the use of object in c++?

566


What is anonymous object in c++?

630


How do you establish an is-a relationship?

616