This is version A of the Midterm Exam. The questions in the other
versions are similar.
True or False Questions, 1 point each
To practice taking this section. Select TRUE or FALSE in the pop-up menus
after each question to record your answer. To submit your answers for
grading, click on the "submit for grading" button.
On lynx, use down arrow to move to the next question or choice.
Hit return to make your selection.
Multiple Choice, 2 points each
To practice taking this section. Choose the best answer in the pop-up
menu after each question to record your answer. To submit your answers
for grading, click on the "submit for grading" button.
On lynx, use down arrow to move to the next question or choice.
Hit return to make your selection.
Short Answers, 4 points each
This section cannot be graded on-line. To practice
taking the exam, jot down your answer and follow the link
after each question to see a sample solution.
In the following questions, no syntax errors have put in
deliberately. (So, "there is a syntax error" is not the right
answer and will receive no credit.)
Please mark your final answer clearly.
In order to receive partial credit, you must show your
work.
Write down the output of the following program fragment.
int i, j ;
for (i = 1 ; i <= 4 ; i++) {
for (j = 1 ; j <= 5 ; j++) {
if ( (i == 1) || (i == 4) ) {
printf("X") ;
} else if ( j == 5 ) {
printf("X") ;
} else {
printf("O") ;
}
}
printf("\n") ;
}
Write a short program with a for loop that takes an
integer value (call it n) from the user and prints out the
first n odd numbers and the sum of the first n odd numbers.
For example, if the user enters 3 as input, your program
should print out:
1 + 3 + 5 = 9
If the user enters 9 as input, your program should print out:
Write down the output of the following complete program.
Show your work and clearly indicate your final answer.
#include <stdio.h>
int lennie (int, int) ;
int squiggy (int) ;
main() {
int a, b, c ;
a = 1 ;
b = 4 ;
c = squiggy(3) ;
a = lennie(b, c) ;
printf("main: a = %d, b = %d, c = %d\n", a, b, c) ;
}
int lennie (int a, int b) {
int c ;
c = squiggy(a - b) ;
printf("lennie: a = %d, b = %d, c = %d\n", a, b, c) ;
return(c) ;
}
int squiggy (int a) {
int b, c ;
b = 3 * a - 1 ;
c = b - a ;
printf("squiggy: a = %d, b = %d, c = %d\n", a, b, c) ;
return(b) ;
}
Write a short program that takes an integer value (call
it n) from the user and prints out a tower of numbers starting
with n on the first line, then n-1 twice on the second line,
then n - 2 three times on the third line, For example, if the
user enters 3 as the input, your program should print out:
3
2 2
1 1 1
If the user enters 5 as the input, your program should print
out: