Docsity

CPSC 206 Quiz 1: Structured Programming in C - Fall '07, Quizzes of Computer Science

Toggle sidebar
bg1
CPSC 206 Structured Programming in C, Fall ’07 Quiz 1 September 10, 2007
Ronnie Ward 2 9/10/2007 1
*** DO NOT LOOK AT THE QUIZ UNTIL INSTRUCTED TO DO SO ***
Last name, First Name ______KEY___________________________________________
Last 4 digits of UIN ____KEY_______ Write your section number: ____501-506______
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: ___________KEY____________________
Date: _____________9/10/2007______________
pf2

Partial preview of the text

Download CPSC 206 Quiz 1: 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 1 September 10, 2007

Ronnie Ward 21 9/10/

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

Last name, First Name ______KEY___________________________________________

Last 4 digits of UIN ____KEY_______ Write your section number: ____501-506______

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: ___________KEY____________________

Date: _____________9/10/2007______________

CPSC 206 Structured Programming in C, Fall ’07 Quiz 1 September 10, 2007

Ronnie Ward 22 9/10/

1. [20] Correct the common programming errors in the following code. Mark only what’s

necessary to correct C syntax errors and insert required C code to avoid compiler

errors/warnings.

#include <stdio.h>

int sum(int a, int b); int main(void) {

int previous, current, max; int i; int next; printf("Input max number: \n” ); scanf("%d", &max); printf("The first %d Fibonacci numbers:\n", max);

/* calculate and print max Fibonacci numbers */ previous = 0; current = 1; for (i = 0; i < max; ++i) { printf("F(%2d) = %d\n", i, previous); next = sum(previous, current); previous = current; current = next; } return 0; } int sum (int a, int b) { int final; int result = a + b; return result; }

2. [5] Briefly describe the action of the following code:

int one = 1; while ( one = 1) one--; sets the variable one to 1, and then sets it alternately to 1 and 0

3. [5] What common programming error is likely present in the code in problem 2?

The while expression should be a logical operator ==, not an assignment = operator.

4. [5] Briefly describe the action of the following code:

int i, sum = 0; for (i = 1; i <= 10; ++i); sum += i; Allocate space for i and sum; initialize sum to 0; set i to 1,

increment i from 2 to 11,terminate the for loop; set sum to 11 (0+11).