




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





Name (printed):
Student ID #:
Section # (or TA’s: name and time)
This is a closed book, closed notes exam. No calculators or other aids are allowed. If you have a question during the exam, please raise your hand. Each question’s value is written next to its number. Watch the number of points for each question to be sure you are not spending too much time on any particular question. It is not necessary to do the problems in the order presented – the order of presentation was selected to give extra space to questions that may need that space. (In particular - the page after a programming question is blank so you can flow onto the second page if needed.)
No one may leave before the exam is over.
There are no syntax errors in any of the C code on this exam. If you don’t recognize a C construct, do the best you can.
pages numbered 1-8, 6 problems, 100 points, 60 minutes.
Please write legibly. Credit cannot be given for any parts of answers which cannot be read.
Good luck!
1 2 3 4 5 6 Total
a. Give the UNIX command which will move you into directory where the class example source files are. You may assume you are in your home directory when you give the command.
b. Write the UNIX command which will allow you to display the contents of the file named this.file to the screen one page at a time. The file named this.file is in your home directory. You do not know which directory you are in as you give the command.
c. Give the command you would type that would compile the program that is named this.c into an executable file named that. The file named this.c is in the current working directory and the executable file can be put in the same directory.
d. There are certain things that are usually at the very top of the source file. i. These often begin with a the # character. What is the purpose of the # character in this context?
ii. One of these is #include - what is the purpose of this?
iii. Another is #define - what is the purpose of this?
e. Give an example of an escape sequence which could appear within a printf string and tell its purpose.
f. Give an example of a format specifier which could appear within a printf string and tell its purpose.
Enter an Integer: - Invaid Input
Enter an Integer: 2 Thank you Enter a Character: x Invalid Input
Enter an Integer: 3 Thank You Enter a Character: a Thank you aaa
Page Blank to leave extra room for the programming question.
if (a < b) if (c < d) statement1; else if (a <= c && a != d) if (a == c) statement2; else statement3; else if (c > d) statement4; else statement5;
a. a = 2, b = 5, c = 3, d = 6
b. a = 3, b = 4, c = 2, d = 1
c. a = 1, b = 1, c = 1, d = 1
d. a = 3, b = 4, c = 5, d = 2
a. i = 0; while (i < 10){ printf("%d - ",i++); i++; }
b. i = 10; j=2; while (i>j*2) printf("%d %d\n",j,i); i -= j;
c. i = 2; j = 7; k = 2; while (i+k <= j){ printf("%d %d %d\n",i, j, k); i++; k+=3; } printf("%d-%d-%d\n",i,j,k);
d. int i = 1; int j = 11; while (i < j/2){ printf("i, j\n"); j-=3; }