SSL Certificate
  • What is wrong with the following while loop
What is wrong with the following while loop if the intention is to print out "C is fun! twice?  (Hint: it is a syntax error.) 
int count = 1;
while (count <= 2);
     printf ("C is fun!\n");
     printf ("%i\n", count);

2.  In the following program, what additional syntax is needed to ensure that two printfstatements in the ifstructure shown will be executed when the condition is false (i.e., when grade < 60). Please make the change right in the code itself.
#include <stdio.h>
void main (void)
     int grade;
     printf ("Enter student grade: ");
     scanf ("%i", &grade);
     if (grade >= 60)

          printf ("You passed.\n"); 
          printf ("Good job\n");


          printf ("You failed\n");
          printf ("You need to improve");

3.  What is output from the following code segment:
for (x = 1; x <= 5; x++)
      if (x != 3)
        printf ("%i  ", x);
} /* end for loop */
printf ("Oh my!");

4.  A group of contiguous memory locations related by the fact that they all have the same name and the same data type is knows as:
a. a variable.
b. an array.
c. a file.
d. a function.
5.  What would be output based on the user input shown below, given that variable "feeling" is a declared as a char. Please place your answer where indicated in the box below (this is a program segment, not a complete program; do not say error or no output).
     printf ("How do you feel (G=Good, S=Sick, T=Tired): ");
     scanf ("%c", &feeling);
     switch (feeling)
          case 'S':   printf ("Take 2 aspirin.\n");
                          printf ("Call me in the morning.\n");
          case 'T':   printf ("Don't stay up late.\n");
                          printf ("Get some sleep!\n");
          case 'G':   printf ("I'm glad for you.\n");
          default:    printf ("**Invalid Feeling**");
Program execution #1:
How do you feel (G=Good, S=Sick, T=Tired): T
(The user entered "S")


Program execution #2:

How do you feel (G=Good, S=Sick, T=Tired): G
(The user entered "R")

6.  To declare array my_values to contain a maximum of 10 floating point numbers, the correct declaration would be: 
a. float my_values[] = {1,2,3,4,5,6,7,8,9};
b. float my_values[10];
c. float my_values[11]; 
d. float my_values[9];

7.  Which statement below  is equivalent to the following code segment: 
if ( ( num % 2) == 0 ) 
     printf ("Even.\n"); 
     printf ("Odd.\n");
a. (num % 2) = 0 ?printf ("Odd.\n") : printf ("Even.\n"); 
b. (num % 2) = 0 :printf ("Even.\n") ? printf ("Odd.\n"); 
c. (num % 2) == 0 ?printf ("Odd.\n") : printf ("Even.\n");
d. (num % 2) == 0 ?printf ("Even.\n") : printf ("Odd.\n"); 

8.  The body of which looping structure is always executed at least 1 time?
a. the do loop
b. the while loop
c. the for loop
d. the if loop

9.  What is printed after the following code segment is executed?
 char  array_values[30] = "QJWAMMDECS$ EBDONNEDXYZW";
 for ( i=1 ; i< 21; i = i + 2)
       printf("%c", array_values[i]);
 printf(" 007\n");
A loop within another loop is known as:
a. a loop-dee-loop.
b. a nested loop.
c. a double loop.
d. a 2-dimensional loop.

Which C statement below causes the program to skip the remaining statements in a loop but does not cause the loop to end(if any).
a. continue;
b. stop;
c. break;
d. exit;

Which C statement below causes any statements following it in the body of the loop to be skipped, but allows the next iteration of the loop to be processed. 
a. continue;
b. exit;
c. goto;
d. break;

Based on the values of condition 1 and condition 2 (T = True, F= False), fill in the remainder of the truth table below with T's or F's.
Condition1 Condition2   Cond. 1 && Cond. 2   Cond. 1 || Cond. 2
       F                 F                                
       F                 T                                 
       T                 F                                
       T                 T                                
Fill blanks above (Answer1 - Answer8) with correct T or F values.
14.  What is output from the following code segment:
for (x = 1; x <= 5; x++)
    if (x != 3)
     printf ("%i  ", x);
} /* end for loop  */
printf ("Greetings");
15.  How do we refer to the second element of the following array:
int grades[3];
a. grades[3]
b. grades[2]
c. grades[1]
d. grades[0]

16.  What is output from the following code segment:
int x = 2, num;
while (x < 6)
     num = x * x;
     printf ("%i\n", num);

17.  What is output from the following code segment? 
intnum = 1;
while (num< 3)
      printf ("**");
printf (" That's all folks!");
18. t is common to confuse the equality operator with the assignment operator because the assignment operator looks like  and the equality operator looks like  

19.  What is output from the following code segment? 
intnum = 3; 
printf ("%i", num); 
num = num + 2; 
} while (num<= 5);
20.  How many elements does array grades[5] have? 
a. 6
b. 4
c. 3
d. 5

21. How would the last line of the following code segment need to be modified for the average calculation below to be correct? (Note: this is not an entire program just a code segment) 
 float average;
int    total = 100, number = 27;
average = total/number;
22.  Assume the logic design below with 'T' representing TRUE. Which conditions must be met in order for this person to get a car.
 if ( (salary > 15000) && (credit_rating>=3) ) 
       new_car = 'T';
a. Person must have at least credit rating 3 and make more than 15000 to get a car.
b. Person has cash so no problem
c. Person can get a car when credit rating is 5.
d. Person can get a car when salary is 16000

23.  A looping structure which allows programmers to specify that an action is to be repeated as long as some condition remains true is known as:
a. a while loop.
b. an if statement.
c. an array.
d. an if/else statement.

24.  ow many values does the following scanfstatement expect the user of the program to input: 
printf("Please enter three numbers: \n");
scanf ("%i%i%i", &x,&y);
a. 3 values
b. 2 values
c. 0 values
d. 1 value

25.  Which of the following statements initializes the entire array nums[4] to zero? (Choose all that apply, look very closely!): 
a. for (i = 0, i< 4, i++) { nums[i] = 0; } 
b. Int nums[ ] = {0,0,0,0};
c. intnums[4] = {0, 0, 0, 0};
d. intnums[4] = {0};

Excellent Solution
*Instant Download

Write a review

Please login or register to review

What is wrong with the following while loop

  • $9.99

*All your data are SECURED & ENCRYPTED using a valid, trusted server certificate (Comodo SSL) and we don't store credit card information on our servers and all Payments are SECURED & handled by Paypal.
SSL CertificatePaypal

Tags: c, programming, multiple choice questions, mcq