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 pointers?
What is the difference between a pointer and a link in c ++?
What programming language should I learn first?
Can the operator == be overloaded for comparing two arrays consisting of characters by using string comparison?
Explain queue. How it can be implemented?
On throwing an exception by the animal constructor in p = new animalq, can memory leak occur?
What is difference between rand () and srand ()?
What is virtual methods?
What is nested class in c++?
What is Destructor in C++?
What is meant by iomanip in c++?
What is a responder chain?
What is pure virtual function? Or what is abstract class?
Why do we need constructors in c++?
Which coding certification is best?