Part I: Multiple Choice (30 Points) : Answer: B
Part I: Multiple Choice (30 Points) : Answer: B
Part I: Multiple Choice (30 Points) : Answer: B
Answer all of the following questions. READ EACH QUESTION CAREFULLY. Fill the correct bubble
on your mark-sense sheet. Each correct question is worth 2 points. Choose the one BEST answer for each
question. Assume that all given C code is syntactically correct unless a possibility to the contrary is
suggested in the question.
Remember not to devote too much time to any single question, and good luck!
A. Char
B. 1st_answer
C. Y2K
D. CSE142_IS_FUN
E. integer
Answer: B
if (x <= 0) printf("Error!");
A. x <= 0 is an expression
B. x <= 0 is an argument to a function
C. x <= 0 is a compound statement
D. x <= 0 is an operator
i. It is a declaration of number
ii. It is an initialization to number
iii. It is a call to the function number
A. i. only
B. ii. only
C. iii. only
i. 2*x is an expression
ii. 2*x is a variable
iii. 2*x is an argument to a function
A. i. only
B. ii. only
C. iii. only
A. 3
B. 3.0
C. 3.9
D. 4
E. 4.0
Answer: C
a+5*a-8
A. (a+5)*(a-8)
B. ((a+5)*a)-8
C. (a)(+5)*(a)(-8)
D. (a+(5*a))-8
E. ((a)+(5))*((a)-(8))
Answer: D
7. Which of the following is the proper heading for a function that has an
integer parameter and returns a value of type double?
A. int foo(x)
B. foo(int x, double y)
C. void foo(int x)
D. double foo(int x)
#include <stdio.h>
A. 7
B. 8
C. 9
D. 12
E. 15
Answer: D
Page 5
double foo(void)
{
int x, y;
double z;
x = 5;
y = 2;
z = (x/y);
z = z+0.2;
return z;
}
A. 2
B. 2.2
C. 2.5
D. 2.7
E. 3.2
Answer: B
10. After executing the following code, what will the value of x be?
int x, y;
double a;
y = 3;
x = y + 2;
a = 2.1;
y = x;
x = x * a;
A. 11
B. 10.5
C. 10
D. 6.3
E. 6
Answer: C
Page 6
A. 3
B. 4.00000
C. 9
D. 9.66666
E. 10
Answer: C
12. Adam Asinment wrote the following version of max which takes three
arguments and (he says) returns the largest. What is true about the value
returned by the function?
D. the function returns the highest of the first and third arguments
A. 72
B. 80
C. 128
D. -128
E. -72
Answer: D
Page 7
14. Suppose x and y are declared as ints, and both are greater than 0.
Which of the following expressions rounds x/y to the nearest integer?
(Examples of rounding to the nearest integer are 6/5 = 1, and 38/10 = 4)
A. (x + 0.5) / y
B. (x + y - 1) / y
C. (x + y / 2) / y
A. 5.50 5
B. 2.50 4 6.50
C. 4 6.50 2.50
D. 2.50 3 5.50
Be sure to use integer (int) and floating-point (double) variables and expressions
appropriately. The final output should have integer values for number of pounds and
ounces. The number of ounces should be between 0 and 15, and any fractions of an
ounce should be discarded (truncated) from the final value. However, be careful to
retain any fractional parts of intermediate results if they are needed to calculate
correct values for the final answers.
/* put any #define macros here (for conversion factors or anything else appropriate)*/
#define LBS_PER_KG 2.2
#define OZ_PER_LB 16
#include <stdio.h>
void main(void) {
}
Page 9