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
What are dynamic type checking?
What is the role of copy constructor in copying of thrown objects?
What does 7/9*9 equal ? a) 1 b) 0.08642 c) 0
What is enum class in c++?
What is a string example?
How does list r; differs from list r();?
If all is successful, what should main return a) 0 b) 1 c) void
Can a function take variable length arguments, if yes, how?
What do you mean by function and operator overloading in c++?
Is c# written in c++?
What is general format for a prototype?
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. --- │ │ │ │ │ │ ---
What is the use of object in c++?
What is anonymous object in c++?
How do you establish an is-a relationship?