Docsity

CPSC 206 Quiz 2: Structured Programming in C Fall ’07, Quizzes of Computer Science

Toggle sidebar
bg1
CPSC 206 Structured Programming in C, Fall ’07 Quiz 2 September 21, 2007
Ronnie Ward 2 9/21/2007 1
************************************************************
* DO NOT LOOK AT THE QUIZ UNTIL INSTRUCTED TO DO SO *
************************************************************
Last name, First Name ____________________________________________________
Last 4 digits of UIN ______________ Write your section number: _________________
The value of individual problems (eg. 10) is shown as [10] next to the problem number.
Do not look at your neighbor’s answers, or share your answers with your neighbor!
If you have a question about a problem, write your question, the answer you are
assuming, and continue. Don’t ask your question aloud in class!
Let me repeat that. Do not ask your questions aloud in class during the quiz!
Verbosity is discouraged. Written answers should in good English. Neatness counts and
we reserve the right to assign lower grades for sloppiness, much lower!
Calculators, PDAs, CD players, radios, and headphones are NOT allowed!
Work quickly! You have only 10 minutes to take this exam.
Remember:
Aggies do not lie, cheat, or steal and do not tolerate those who do!
I have obeyed the Aggie code of honor in my answers on this quiz.
Signature: ___________________________________
Date: ___________________________________
pf2

Partial preview of the text

Download CPSC 206 Quiz 2: Structured Programming in C Fall ’07 and more Quizzes Computer Science in PDF only on Docsity!

CPSC 206 Structured Programming in C, Fall ’07 Quiz 2 September 21, 2007

Ronnie Ward 21 9/21/

* DO NOT LOOK AT THE QUIZ UNTIL INSTRUCTED TO DO SO *

Last name, First Name ____________________________________________________

Last 4 digits of UIN ______________ Write your section number: _________________

The value of individual problems (eg. 10) is shown as [10] next to the problem number.

Do not look at your neighbor’s answers, or share your answers with your neighbor!

If you have a question about a problem, write your question, the answer you are

assuming, and continue. Don’t ask your question aloud in class!

Let me repeat that. Do not ask your questions aloud in class during the quiz!

Verbosity is discouraged. Written answers should in good English. Neatness counts and

we reserve the right to assign lower grades for sloppiness, much lower!

Calculators, PDAs, CD players, radios, and headphones are NOT allowed!

Work quickly! You have only 10 minutes to take this exam.

Remember:

Aggies do not lie, cheat, or steal and do not tolerate those who do!

I have obeyed the Aggie code of honor in my answers on this quiz.

Signature: ___________________________________

Date: ___________________________________

CPSC 206 Structured Programming in C, Fall ’07 Quiz 2 September 21, 2007

Ronnie Ward 22 9/21/

1. [10] Examine the following program. Recall, for a postfix decrement operator, the

current value of the variable is “used” to determine the value of the expression before the

decrement is applied to its operand. What is printed?

#include <stdio.h> int main(void) { int k = 1, j;

while (k--){ j = printf("%d ", k); printf("%d ", j); } printf("%d ", k); return 0; }

2. [10] Examine the action of the following code. Identify what values are NOT printed

by marking an X thru these choices: 10 0 1 2 3

X X

#define MAX 10 #define MIN 0 #include <stdio.h> int main(void) { int one = 1, two = 2, three = 3; if (MIN || (one = two % three)) printf("%d %d %d\n", MIN, one, three); else printf("%d %d %d\n", MAX, one, two); return 0; }

3. [10] Examine the action of the following code. What does the program print?

#include <stdio.h> int main(void) { int k, sum; for(sum = 0, k = 1; k <= 2; sum -= k, k += 1); printf("%d\n", sum); return 0; }

Working Area

k = 1, 0, - j = 2, print: 0 2 -

Working Area

one = 1, 2 two = 2 three = 3 print:

Working Area

k = 1, 2, 3 sum = 0, -1, - print: