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 runtime polymorphism in c++?

0 Answers  


What is stoi in c++?

0 Answers  


write asingle linked list which read from two list & the do the following 1 sort the prime & nonprime num (prime should be less tn nonprime) 2 each node has a prime num followd by nonprime 3 add a new node into its sutable plce 4 erase the most three duplicated non prime num 5 find the least duplicated prime num

0 Answers   Care,


what is data encapsulation in C++?

0 Answers  


What you mean by early binding and late binding? How it is related to dynamic binding?

1 Answers  






What are the difference between reference variables and pointers in C++?

1 Answers  


Do the names of parameters have to agree in the prototype, definition, and call to the function?

0 Answers  


If P is the population on the first day of the year, B is the birth rate, and D is the death rate, the estimated population at the end of the year is given by the formula: The population growth rate is given by the formula: B – D Write a program that prompts the user to enter the starting population, birth and death rates, and n, the number of years. The program should then calculate and print the estimated population after n years. Your program must have at least the following functions: 1. growthRate: This function takes its parameters the birth and death rates, and it returns the population growth rate. 2. estimatedPopulation: This function takes its parameters the current population, population growth rate, and n, the number of years. It returns the estimated population after n years Your program should not accept a negative birth rate, negative death rate, or a population less than 2.

1 Answers  


What is the role of copy constructor in copying of thrown objects?

0 Answers  


Explain some examples of operator overloading?

0 Answers  


In a function declaration what does extern means?

0 Answers   Flextronics,


Difference between const char* p and char const* p?

1 Answers  


Categories