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.



Given the following seqment of code containing a group of nested if instructions: y = 9; if ((x==3..

Answer / 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

More C++ General Interview Questions

What is an iterator?

0 Answers  


How do you establish an is-a relationship?

0 Answers  


What is a protocol class?

1 Answers  


You run a shell on unix system. How would you tell which shell are you running?

0 Answers  


write a program that will produce the ff. output. "what fruit will you buy? 1)apple 2)orange 3)mango ENTER CHOICE (1,2 or 3)> HOW MANY WILL YOU BUY?> THAT WILL COST XX.XX

1 Answers  






Is it possible for a member function to use delete this?

0 Answers  


Write a corrected statement in c++ so that the statement will work properly. x + y=z;

2 Answers  


There is a array of 99 cells and we have to enter 1-100 elements in it , no two elements would repeat , so the is one no. missing because 99 cells and 1-100 nos. so we had to implement a function to find that missing no.

2 Answers   Nagarro,


if i want cin 12345678910 and cout abcdefghij. so how can i create the program?. example : if i key in 8910 so the answer is ghij.

3 Answers  


which is the easy way to divide any integer by 2?

2 Answers   Persistent,


Will a recursive function without an end condition every quit, in practice a) Compiler-Specific (Some can convert to an infinite loop) b) No c) Yes

0 Answers  


Is c++ vector dynamic?

0 Answers  


Categories