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 the rules for naming an identifier?
What are c++ templates used for?
What's the order in which the local objects are destructed?
What is malloc in c++?
How do you find out if a linked-list has an end? (I.e. The list is not a cycle)
what are the characteristics of Class Members in C++?
What is istream and ostream in c++?
What does the ios::ate argument do?
What is flush c++?
What is the benefit of encapsulation?
What are the advantages of using const reference arguments in a function?
Should I learn c or c++ first?
What is static function? Explain with an example
What is the best c++ compiler?
What is vector processing?