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

List the issue that the auto_ptr object handles?

761


How would you use qsort() function to sort an array of structures?

850


Why should you learn c++?

740


What is buffer and example?

654


What is wrapper class in c++?

763






Mention the storage classes in c++.

791


Can we use struct in c++?

734


What are all predefined data types in c++?

712


What is implicit pointer in c++?

764


What does it mean to declare a member function as virtual?

732


Is it possible for a member function to delete the pointer, named this?

767


What does the following code do: int c=0; cout< a) Undefined *Updated* b) 01 c) 00

775


What are the c++ access specifiers?

984


Is map thread safe c++?

803


What things would you remember while making an interface?

721