Lab 7 Answer Sheet -- Solutions

Part 1: Prelab

(Each blank is worth 1/6 point. Part 1 is worth 3 points)

Part A: Operations on integer values

1.
a) Answer: _________ Placement 0____________________ (computations involving only integers return integer values)


b) Answer: _________ 3 Placement ____________________ (notice that the %i controls where the integer appears on the computer screen 


c) Answer: ____________5_________________ ( % means "remainder" just like doing 5th grade math)


d) Answer: ___________x = 1.234568___________________


e) Answer: ________Your cost = $1.2346______________________


f) Answer: ________Forgetting the change = $1______________________


g) Answer: ____________x = 1.23456788__________________


h) Answer: ___________y = 1.2345678912 ___________________


i) Answer: ____________x = -0.000000___________________


j) Answer: __________y = 1.234568____________________


k) Answer: __________6:5:1____________________


l) Answer: ____________06:05:01__________________

 

=====================================================================

 

Part B: If, nested if and switch statements

2.


m) ____________Non-negative!______________________________


n) _____________Not equal!_____________________________


o) _____________Two_____________________________




3.


p) _____________Positive!_____________________________



q) _____________Equal!____________________________



r) _____________Two Three Not valid!____________________________


Part 2: Simple C programs

 

(1/3 point per blank(18 blanks) , 6 points for Part 2)

 

Part A.

1.

a) _____________Odd!____________________________




b)           The input is a multiple of Two, Three, and Five!_____




c) _____________Two_____________________________

 

2.

 

d) __________Negative Number!________________________________




e) __________Not equal to zero!_______________________________




f) __________One Two Three Not valid!_______________________________

=====================================================================

Part B.


1.


____nickels = cents / 5;_____________ /* nickels */



____if (nickels > 0)____________________________/* nickels */



________printf %i nickels_____or variations like printf("%i \n", nickels);___________________/* nickels */



pennies = _____cents % 5;__________________/* pennies */



if ( _______pennies > 0_____________________ ) /* pennies */



_________printf %i pennies_____or variations like printf("%i \n", pennies);______________/* pennies */



2.

__________4__________ quarters


___________1_________ dimes


___________1_________ nickels


_________2___________ pennies

 

=====================================================================

Part C.


3.


input = 2/3/8 output = _________02/03/2008___________________________________


input = 12/7/96 output = ________12/07/1996____________________________________