UMBC CMSC201, Computer Science I, Spring 1994 Sections 0101, 0102 and Honors

Midterm Exam, 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.

There are no intentional syntax errors in this section. Answers like ``There is no output, because there is a syntax error'' will receive 0 credit.


  1. What is the output of the following code?
        int i, j ;
        
        for (i = 0 ; i < 5 ; i++) {
           for (j = 0 ; j < 5 ; j++) {
              if ( i * i >= j) {
                 printf("X") ;
              } else {
                 printf("O") ;
              }
           }
           printf("\n") ;
        }
      

    Click here for a sample solution.

  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 foobar(int a) ;
        int geez(int b) ;
        
        main() {
           int a = 1, b = 2, c = 3 ;
           
           c = geez(a) ;
           b = foobar(c) ;
           printf("main: a = %d, b = %d, c= %d\n", a, b , c) ;
        }
        
        int foobar (int b) {
           int a, c ;
           
           a = geez(b) ;
           c = b++ ;
           printf("foobar: a = %d, b = %d, c = %d\n", a, b, c) ;
           return(c) ;
        }
        
        int geez (int c) {
           int a, b ;
           
           a = c + 100 ;
           b = 2 * a ;
           printf("geez: a = %d, b = %d, c = %d\n", a, b, c) ;     
           return(a) ;
        }
      

    Click here for a sample solution.

  3. Write a simple loop to print out the following numbers. (Hint: this is the first part of the sequence of the squares of odd numbers.)
          1 9 25 49 81 121 169
    

    Click here for a sample solution.

  4. Write a simple function called CubeRoot which takes an int argument n and returns the largest integer whose cube is smaller than n. For example, CubeRoot(9) should return 2 because 2*2*2 = 8 < 9 < 27 = 3*3*3. Similarly, CubeRoot(119) should return 4.

    Click here for a sample solution.


Last Modified: Mon Sep 4 15:54:28 EDT 1995

Richard Chang, chang@gl.umbc.edu