Here are a few example possible midterm questions. The first couple might be too easy.

1. State two distinct uses of "comments" in computer programs.

2. How many times does a loop "for (i = 10; i < 20; i += 3)" iterate?

3. Here is a C program. Trace the execution of this program by listing all of the values assigned to "x", in order.

int main()
{
    int x;
    x = 1;
    while (x < 11)
        x = x + 3;
    if (x < 9)
        x = 5;
    else
        x = 7;
    while (x < 10)
        x = x + 4;
    return 0;
}

4. Write a C function (not a complete program, but a complete function) which finds the first prime number greater than its parameter, using a loop. Your function will call a function isprime() which returns 1 or 0 to indicate whether or not its single integer argument (parameter) is prime, just like in lab ???. Your function will take one argument which is an int and will return an int. Assume that the argument is at least 2. (Do not write a main(), the isprime() function, or any printf or scanf calls.)


[main course page]