Here are some good questions taken from past EE150 midterms that you can use as practice for the current midterm. A real EE150 midterm is longer than this sample exam, so you should shoot for being able to do these sample questions in under 40 minutes.
What do each of the following main programs print? Show the output BELOW the program in the space provided. Show your work to the right of the program using the "boxes" approach discussed in class. You get no points if you fail to draw boxes for each variable and show us exactly how its value changes.
int table[8] = {87, -1, 94, 0, 80, 1, 90, 70};
main()
{
int i;
for (i = 7; i >= 0; i--)
{
if (table[i] > 75)
printf("%i\n", table[i]);
if (table[i] <= 0)
break;
}
}
main()
{
int weird(int x, int y);
for (i = 0; i < 6; i++)
{
if (i >= 3 && i <= 4)
printf("%i-a\n", i);
if (i >= 3 || i <= 4)
printf("%i-b\n", i);
}
}
Show us the minimum set of changes that we must make to each of these programs to get them to compile successfully and run exactly as their comment describes. That is, you should show us what we have to add, delete, or replace to make these fucntions work! HINT: Each function has 4 mistakes.
/*
* Print the number of digits found in this program's input.
*/
#include <stdio.h>
main()
{
int count;
int c;
c = getchar();
while (c != EOF)
if (isdigit(c) == 0)
count = c + 1;
printf("Found %i digits in input\n", count);
return 0;
}
/*
* Count the number of negative values in an array "table" that
* contains "n" elements. Return this count.
*/
int count_negatives(int table[], int n)
{
int count;
count = 0;
for (i = n - 1; i > 0; i--)
if (a[i] > 0)
count++;
return i;
}
#######
7
###
3
############
12
control-D
There were 3 bars with an average length of 7.
You may assume that n will be at least 1.int maxvalue(int table[], int n);
[EE150 Home Page | EE150 Exam Information Page | Top Of Page]