![]() |
CMSC104Problem Solving & Computer Programming |
- Question: For what exact range of values of variable x does the following code segment display the letter 'C'?
Choose the best Answer :
if (x <= 200) if (x < 100) if (x <= 0) printf("A\n"); else printf("B\n"); else printf("C\n"); else printf("D\n");
- 0 < x < 100
- x <= 0
- 100 <= x <= 200
- x > 200
- 100 < x <= 200
- Question: If num is a variable of type int and temp is a variable of type double, how could you correctly complete this function call?
Choose the best Answer :
scanf("%lf%d", _________);
- num, temp
- &num, &temp
- temp, num
- &temp, &num
- none of the above
- Question: If the value of control is 5, the following switch statement will cause a run-time error.
Choose the best Answer :
switch (control) { case 1: printf("one"); break; case 2: printf("two"); break; case 3: printf("three"); break; case 4: printf("four"); }
- true
- false
- Question: The following decision statement is coded correctly:
Choose the best Answer :
if x <= y printf("%f", x); else printf("%f", y);
- true
- false
- Question: The following program segment gives x and y the same value if the condition is true:
Choose the best Answer :
if (x > y) { y = x; x = y; }
- true
- false
- Question: What does the following if statement display?
Choose the best Answer :
if (13 < 12) printf("never\n"); else printf("always\n");
- never
- always
- Question: What is displayed by the C statements that follow if the input value is 2?
Choose the best Answer :
scanf("%d", &ctl); switch (ctl) { case 0: case 1: printf("red "); case 2: printf("blue "); case 3: printf("green "); case 4: printf("yellow"); } printf("\n");
- red
- blue
- green
- yellow
- blue green yellow
- Question: What is the program output if the user types runt followed by a carriage return when the program is run?
Choose the best Answer :
char r, x, y, z, w; scanf("%c%c%c%c", &x, &y, &z, &w); if (x < y) r = x; else r = y; if (r > z) r = z; if (r > w) r = w; printf("%c\n", r);
- r
- u
- n
- t
- none of the above
- Question: What is displayed by the C statements at the right if the value input is 3?
Choose the best Answer :
scanf("%d", &n); if (n = 5) { printf("Equal\n"); } else if (n < 5) { printf("Less\n"); } else { printf("Greater\n"); }
- Equals
- Less
- Greater
- no output
- Question: If the input to the program segment at the right is 85, what is its output?
Choose the best Answer :
scanf("%d", &s); if (s >= 90) printf("A\n"); else if (s >= 70) printf("C\n"); else if (s >= 80) printf("B\n"); else printf("D\n");
- A
- B
- C
- D
- Question: What will be the value of i after the C statements at the right have been executed?
Choose the best Answer :
i = 3; j = 10; if ((3 * i) < j) { i = i + 2; } i = i + 3;
- 5
- 6
- 8
- 10
- 15
- Question: Assuming that A = 1 and B = 1,
Choose the best Answer :
- (A and B) is FALSE, while (A or B) is TRUE
- (A and B) is FALSE, while (A or B) is FALSE
- (A and B) is TRUE, while (A or B) is TRUE
- (A and B) is TRUE, while (A or B) is FALSE
- Question: Text enclosed in /* */ in a C program _________.
Choose the best Answer :
- gives instructions to the processor
- declares memory requirements
- makes files available
- causes a syntax error
- is ignored by the C compiler
- Question: The constant 0.15e+6 represents the same value as __________.
Choose the best Answer :
- 150000
- 6.15
- 0.75
- 0.21
- none of the above
- Question: The symbol = is the C equality operator.
Choose the best Answer :
- true
- false
- Question: This assignment statement stores the sum of b and c in a:
Choose the best Answer :
b + c = a;
- true
- false
- Question: Which one of the following expressions does not evaluate to 3?
Choose the best Answer :
- 2 + 16 % 5
- 7 - 15 / 4
- 6 * 5 / 10
- 2 - 4 * 3 + 26 / 2
- 8 - 5
- Question: "All values stored in memory are represented as binary strings, patterns of zeros and ones."
Choose the best Answer :
- true
- false
- Question: A type char literal is enclosed in single quotes.
Choose the best Answer :
- true
- false
- Question: What is the effect of the following code?
Choose the best Answer :
int i, total ; for (i = 1 ; i <= 15 ; i++) { if ( i % 3 == 0) { printf("%d ", i) ; } } printf("\n\n");
- It prints out the integers from 3 to 15
- It prints out the multiples of 3 from 3 to 15
- It prints out the sum of the integers from 3 to 15
- It prints out the sum of the multiples of 3 from 3 to 15