# Midterm Exam, version 1, Short Answer Section

## Short Answers, 4 points each

This section cannot be graded on-line. To practice taking the exam, jot down your answer and click on the button after each question to see a sample solution.

1. What is the output of the following code fragment?
```    int i, j ;

for (i = 1 ; i <= 3 ; i++) {
for (j = 1 ; j <= 5 ; j++) {
if ( 2 * i + j  <= 7) {
printf("+") ;
} else {
printf("o") ;
}
}
printf("\n") ;
}
```

2. Write down the output of this program. Show your work and clearly indicate your final answer.
```    #include <stdio.h>
#include "genlib.h"
#include "simpio.h"

int deep(int, int) ;
int space(int) ;

main() {
int a = 1, b = 2, c = 3 ;

a = deep(b + 5, c) ;
b = space(c) ;
printf("main: a = %d, b = %d, c= %d\n", a, b , c) ;
}

int deep (int x, int y) {
int z ;

z = x - y ;
printf("deep: x = %d, y = %d, z = %d\n", x, y, z) ;
return(z) ;
}

int space (int c) {
int a, b ;

a = 1 ;
b = c * 2 + a ;
a = b + 5 ;
c = deep(a, b) ;
printf("space: a = %d, b = %d, c = %d\n", a, b, c) ;
return(b) ;
}

```

3. Write a simple program with a for loop that asks the user for an integer n and prints out the sum of the odd numbers from 1 to n. (For example: if the user enters 10, then your program should output 25, because 1 + 3 + 5 + 7 + 9} is 25.

4. Write a program that prints out a large plus sign using the + character. Your program should accept an integer n from the user, and print out a plus sign that has n +'s in each arm. The following are sample outputs of the program. User enters 3:
```   +
+
+
+++++++
+
+
+
```
User enters 5:
```     +
+
+
+
+
+++++++++++
+
+
+
+
+
```