CSCE A201 Midterm #1 v2Name:
This exam is worth a total of 100 points. The exam is open book and open notes. You
can use a calculator or a computer but should be your own work. Show your work or
thought processes. You can insert your answers into this document and upload your final
answers or upload your answers in a separate document(s) that are compressed into a
single zip file.
1) 20 points. Short Answer.
a) What could go wrong with the code:
if (strvar == “hello”)
printf(“Hi there!\n”);
b) Add parenthesis to the expression below to match the order that will be used in C
when evaluating the expression.
3 + 5 % 2 * 10
c) A variable of type char is used to store a character. Why does C allow you to
assign a number to a char variable, for example, char c = 65; ?
d) Fill in the blanks for the program below. The program should calculate the
product of the even integers from 1 to 15 (i.e. 2*4*6*8*10*12*14) and print it.
#include “stdio.h”
int main()
{
int product = ________;
for (int i=1; i 0)
{
value = value + count;
count = count – 2;
}
printf(“Value: %d\n”, value);
3) 20 points. Bugs! Find and fix the bugs in the following code snippets.
a) The following code should output “big” if the input is exactly 100 and “small”
otherwise:
int value;
scanf(“%d”,&value);
if (value = 100)
printf(“big\n”);
else
printf(“small\n”);
b) The following code should keep asking the user to enter a key until the key pressed
is ‘Y’ or ‘N’, at which point the loop should exit.
char c;
do
{
printf(“Try again? Press Y or N.\n”);
scanf(” %c”,&c);
} while ((c!=’Y’) || (c!=’N’));
c) The following should input 5 numbers into the array.
int a[5];
int temp;
for (int i = 1; i