Training high school teachers to teach AP Computer Science Principles
Select Page
Programming Quiz
Results
#1 The prices of two products x and y are 125 and 110 respectively. But the prices of x and y are incorrectly entered as 110 and 125 respectively by the programmer while calculating the profit and loss from both the products. How can the programmer correct the values of x and y?
int dummy=x, x = y, y = dummy
int dummy = x, y = x, x = dummy
int dummy = x, y = dummy, x = y
#2 What is the output of the following code segment?
10010 – UMN 76777 – Uark
10010 – Uark 76777 – UMN
Uark – 10010 UMN – 76777
Uark – 76777 UMN – 10010
#3 What will be the output of each of the code fragments?
(i) 0 (ii) 1
(i) 0 (ii) 0
(i) 1 (ii) 1
(i) 1 (ii) 0
#4 Consider the following code segment and determine the value of the function call min(max(a,b), max(x,y)). If a = 100, b = 0, x = 67, y = 33.
100
0
67
33
#5 Which of the following correctly uses an assignment operator with the values m and n?
m == n
m = n
m && n
Both A and C
#6 What will be the value of count after the execution of the following code segment?
5 times
5^2 times
5^3 times
i+j+k times
#7 What is the value of sum after executing the following code?
The sum: 32
The sum: 8
The sum: 16
The sum: 24
#8 Given the function “fun”, what will be the output of fun (16) ?
16 12 8 4 0
0 4 8 12 16
0
16
#9 Consider the following code segment. What will be printed as a result when the code is executed?
2 4 6 8 10
1 3 5 7 9
1 2 3 4 5 6 7 8 9 10
1 3 5 7 9 10
#10 [8, 1, 10, 6, 4, 2] Assume that these are the elements of a stack ‘S’ such that 2 is the top most element and 8 is the element at the bottom of the stack. Note that, push(), pop(), peek() are the methods used with the stack; push(int x) inserts an integer x onto the top of the stack; int pop() removes the integer at the top of the stack and returns that integer; int peek() returns the integer at the top of the stack without removing it from the stack. How does the Stack look like after executing the following code segment?