Sample Midterm Exam
parks

1 (30 Points) Given:

int fred [1001] = {14, 17, 541, 890, ... pretend there are 993 more here..., 319, 542, 3, 71}

Show the complete C program to display the largest, next largest and third largest integers in fred on the screen. Label the items in your output display. There may be ties. Show all declaractions.

2. (40 points) Using putpixel (x,y) as your only drawing tool, construct the outline of a white square box 200 x 200 pixels centered in the screen. Fill the box with red diagonal strips. These stripes should be five horizontal pixels wide and three horizontal pixels apart. The diagonal stripes make a 45 degree angle with the horizon. The stripes are to be angled from the lower left to the upper right (like this / not this \). The background should be black and the box outlined in white. Omit the initgraph processes.

3. (30 points) The C function:

int random (int num)

generates and returns random integers between 0 and (num-1). Construct a complete C program to generate 10,000 random integers between 1 and 10 inclusive. Count the number of 1’s, 2’s, etc. generated by the random function. Display for each value (i.e., 1, 2,...10) the percentage of random numbers for that value. The display should appear:

xx.xx percent 1
xx.xx percent 2
.
.
.
xx.xx percent 10

Show all declarations.


Return to Syllabus