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

Question 2
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.) Modify the code in the box below.
float average;
int    total = 100, number = 27;
average = total/number;

Question 3
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 can get a car when salary is 16000

c. Person has cash so no problem

d. Person can get a car when credit rating is 5.

Question 4
What is output from the following code segment:
int x = 2, num;
while (x <= 4)
{
num = x * x;
printf ("%i\n", num);
x++;
}

Question 5
What is wrong with the following while loop?
(Hint: it is a logic error, not a syntax error.)
int count = 1;
while (count <= 2)
{
printf ("C is fun!\n");
printf ("%i\n", count);
}

Question 6
What is output from the following code segment?
intnum = 3;
do
printf ("%i", num);
num = num + 2;
} while (num<= 5);

Question 7
What is printed after the following code segment is executed?
inti;
char  array_values = "QJWAMMDECS\$ EBDONNEDXYZW";
for ( i=1 ; i< 21; i = i + 2)
printf("%c", array_values[i]);
printf(" 007\n");

Question 8
Which of the following statements initializes the entire array nums to zero? (Choose all that apply, look very closely!):

a. intnums = {0};

b. for (i = 0, i< 4, i++) { nums[i] = 0; }

c. intnums = {0, 0, 0, 0};

d. intnums[ ] = {0,0,0,0};

Question 9
Which statement below  is equivalent to the following code segment:
if ( ( num % 2) == 0 )
printf ("Even.\n");
else
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 ("Even.\n") : printf ("Odd.\n");

d. (num % 2) = 0 ?printf ("Odd.\n") : printf ("Even.\n");

Question 10
A loop within another loop is known as:

a. a nested loop.

b. a 2-dimensional loop.

c. a loop-dee-loop.

d. a double loop.

Question 11
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               false                 false
F                 T               false                 True
T                 F               false                 True
T                 T               True                True
Fill blanks above (Answer1 - Answer8) with correct T or F values.

Question 12
In the following program, what additional syntax is needed to ensure that two printf statements in the if structure shown will be executed when the condition is false (i.e., when grade < 60). Please make the change right in the code itself.

Question 13
The body of which looping structure is always executed at least 1 time?

a. the do loop

b. the for loop

c. the if loop

d. the while loop

Question 14
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/else statement.

c. an if statement.

d. an array.

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

Question 16
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. an array.

b. a variable.

c. a function.

d. a file.
Question 17
How many elements does array grades have?

a. 5

b. 4

c. 6

d. 3

Question 18
Which C statement below causes the program to immediately exit from a loop, but continue processing the remainder of code in the program (if any).

a. stop;

b. exit;

c. continue;

d. break;

Question 19
What is output from the following code segment?
intnum = 1;
while (num< 3)
{
printf ("**");
num++;
}
printf (" That's all folks!");

Question 20
Which C statement below causes any statements following it in the body of the function to end and control then is passed back to the calling function.

a. return;

b. exit;

c. continue;

d. break;

Question 21
To declare array my_values to contain a maximum of 10 floating point numbers, the correct declaration would be:

a. float my_values;

b. float my_values;

c. float my_values[] = {1,2,3,4,5,6,7,8,9};

d. float my_values;

Question 22
How do we refer to the second element of the following array:

Question 23
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");
break;
case 'T':   printf ("Don't stay up late.\n");
printf ("Get some sleep!\n");
break;
case 'G':   printf ("I'm glad for you.\n");
break;
default:    printf ("**Invalid Feeling**");
break;
}

Program execution #1:
How do you feel (G=Good, S=Sick, T=Tired): T
(The user entered "T")

Program execution #2:

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

Question 24
It is common to confuse the equality operator with the assignment operator because the assignment operator looks like ____ ____ and the equality operator looks like ________ ___________

Question 25
How many values does the following scanf statement expect the user of the program to input:
scanf ("%i%i%i", &x,&y);

a. 0 values

b. 3 values

c. 2 values

d. 1 value

Excellent Solution
================

## Write a review  