Question: Help me with the following C programming questions? Multiple Choice 1. What is wrong with the following? It tries to print out the word for

Help me with the following C programming questions?

Multiple Choice

1. What is wrong with the following? It tries to print out the word for each number but has a bug.

int n = 2;

switch(n)

{

case 1:

printf("one ");

case 2:

printf("two ");

case 3:

printf("three ");

}

a. There should be a break at the end of every case.

b. There should be a default case.

c. You need at least 2 statements in every case.

d. There must be cases for all the numbers from 1 to 10.

2.

double d = 6;

switch(d)

{

case 5:

printf("five ");

}

a. There needs to be a case for 6.

b. There should be a default case.

c. You cannot use a double in a switch.

d. You need a break at the end of the case

3. The following tries to handle an option, and print an error if the option is not recognized. How do we fix it?

int option = 2;

switch(option)

{

case 1:

printf("doing option 1 ");

break;

case 2:

printf("doing option 2 ");

break;

}

printf("Unrecognized option(should be 1 or 2 ");

a. The final printf should be in a default case.

b. There should be an "else" before the final printf.

c. The final printf should be at the end of the second case.

d. There is nothing wrong.

4. On which line is the if with which the else on line 6 is matched?

01 if(a < b) printf("a );

02 if(c > d) printf("b ");

03 else

04 printf("c ");

05 if(e < f) printf("d ");

06 else printf("e ");

a. 02

b. 04

c. 05

d. 01

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!