Name: ________________________ Netid:
_______________ Section: _______
Name: ________________________ Netid:
_______________ Section: _______
Name: ________________________ Netid: _______________ Section: _______
1.
a) Answer: _____________________________ (computations involving
only integers return integer values)
b) Answer: _____________________________ (notice that the %i controls where the integer appears on
the computer screen
c) Answer: _____________________________ (
% means "remainder" just like doing 5th grade math)
d) Answer: ______________________________
e) Answer: ______________________________
f) Answer: ______________________________
g) Answer: ______________________________
h) Answer: ______________________________
i) Answer:
______________________________
j) Answer: ______________________________
k) Answer: ______________________________
l) Answer: ______________________________
2.
m) ______________________________
n) ______________________________
o) ______________________________
3.
p) ______________________________
q) ______________________________
r) ______________________________
1. The following program compiles and runs without errors. Write the ouput the following code produces.
#include <stdio.h>
void main(void)
{
int num;
num = 8;
if (num%2)
printf("Odd!");
num = 9;
if (
num%2)
printf("Odd!\n");
else
printf("Even!\n");
num = 30;
if (num%2
)
{
printf("Not multiple of Two\n");
}
else if ( num%3
)
{
printf("Not multiple of Three\n");
}
else
if ( num%5)
{
printf("Not multiple of Five\n");
}
else
{
printf( "The input is a multiple of
Two, Three, and Five!\n" );
}
num = 2;
switch(num)
{
case
1: printf("One ");
break;
case
2: printf("Two ");
break;
case
3: printf("Three ");
break;
default:
printf( "The input is not valid! "
);
}
printf("\n");
}
Write the output of the program (above).
a)
______________________________
b) ______________________________
c) ______________________________
d) ______________________________
e) ______________________________
f) ______________________________
1. Complete the algorithm for the change program.
float amount;
int cents;
int quarters, dimes, nickels,
pennies;
printf Enter the amount:
scanf %f amount
amount = amount + .005 /* correct for any round-off errors */
cents = 100 * amount
quarters = cents / 25;
if (quarters > 0)
printf %i
quarters;
cents = cents % 25;
dimes = cents / 10
if ( dimes > 0)
printf %i
dimes
cents = cents % 10
______________________________
______________________________
______________________________
pennies = _______________________/* pennies */
if ( ____________________________ ) /* pennies */
______________________________
2. Our program is not just supposed to work for values less than
1.00. Try entering 1.17 into your program and write the
response.
(some blanks may be left empty)
____________________ quarters
____________________ dimes
____________________ nickels
____________________ pennies
3. Write the results you obtain when you enter the following
input to your program:
input = 2/3/8output =
______________________________
input = 12/7/96 output =
______________________________