Digital Music Programming

Mid-term Exam (Fujinaga 1996)

1. Find the error in the following, specify syntactical or semantic errors (10 pnts):

#include <stdio.h>

define MAX 10

int main(null)

{

int i; j; vec[MAX];

for (i = 1; i <= max, i++);

{

list[i] = 2 * i + 3 % i;

for (j= 1, j >=i, j++)

print("%d/n". *(vec + j));

retrun(0.)

}

2. What does the following print (12 pnts)?

#include <stdio.h>

main()

{

int num = 9;

int *pnum = &num;

printf("%d\n", num);

printf("%d\n", -num);

printf("%d\n", ++num);

printf("%d\n", num++);

printf("%d\n", num--);

printf("%d\n", --num);

printf("%d\n", *pnum);

printf("%d\n", *&num + *pnum);

printf("%d\n", &num - pnum);

printf("%d\n", num = 6);

printf("%d\n", num * num);

printf("%d\n", --num + num++);

}

3. Write a program using at least two functions (other than main()) that prompts the user for number in seconds and prints out the number in hours:minutes:seconds format (10 pnts).

Digital Music Programming

Mid-term Exam (Fujinaga 1996) (cont.)

4. (12 pnts)

a) Convert binary 1010110 to decimal

b) Convert binary 1011101 to hexadecimal

c) Convert hexadecimal 0xC2 to decimal

d) Convert hexadecimal 0x5E to binary

e) Convert decimal 97 to hexadecimal

f) Convert decimal 89 to binary

5. What does the following print (10 pnts)?

#include <stdio.h>

int main(void)

{

int i = 0;

while (++1 < 5)

printf("%d ", i % 2);

do

printf("%d ", i % 3);

while ((i-- > 0) ? 3 : 0);

return(0);

}

6. Evaluate the following expressions (6 pnts):

a) 34 / 6

b) 6 / 34

c) 34 % 6

d) 6 | 34

e) 34 || 6

f) 6 < 34