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 inline functions? What is the syntax for defining an inline function?
What is flag in computer?
List the types of polymorphism in c++?
What do you mean by a template?
what is COPY CONSTRUCTOR and what is it used for?
What is the extraction operator and what does it do?
What are the unique features of C++.
Specify some guidelines that should be followed while overloading operators?
How the programmer of a class should decide whether to declare member function or a friend function?
Can constructor be static in c++?
Can malloc be used in c++?
Can you pass an array to a function in c++?
How static variables and local variablesare similar and dissimilar?
Draw a flow chart and write a program for the difference between the sum of elements with odd and even numbers. Two dimensional array.
What is class and structure in c++?