Starting from:

$34.99

NYU-CS Homework 2 Solution


Question 2:
Write a program that asks the user to enter an amount of money in the format of dollars and remaining cents. The program should calculate and print the minimum number of coins (quarters, dimes, nickels and pennies) that are equivalent to the given amount.
Hint: In order to 5ind the minimum number of coins, 5irst 5ind the maximum number of quarters that 5it in the given amount of money, then 5ind the maximum number of dimes that 5it in the remaining amount, and so on.
Your program should interact with the user exactly as it shows in the following example: Please enter your amount in the format of dollars and cents separated by a space:
4 37
4 dollars and 37 cents are:
17 quarters, 1 dimes, 0 nickels and 2 pennies
Question 3:
Suppose John and Bill worked for some time and we want to calculate the total time both of them worked. Write a program that reads number of days, hours, minutes each of them worked, and prints the total time both of them worked together as days, hours, minutes.
Hint: Try to adapt the elementary method for addition of numbers to this use.
Your program should interact with the user exactly as it shows in the following example:
Please enter the number of days John has worked: 2
Please enter the number of hours John has worked: 12
Please enter the number of minutes John has worked: 15
Please enter the number of days Bill has worked: 3
Please enter the number of hours Bill has worked: 15
Please enter the number of minutes Bill has worked: 20
The total time both of them worked together is: 6 days, 3 hours and 35 minutes.
Question 4:
Write a program that reads from the user two positive integers, and prints the result of when we add, subtract multiply, divide, div and mod them.
Your program should interact with the user exactly as it shows in the following example:
Please enter two positive integers, separated by a space:
14 4
14 + 4 = 18
14 – 4 = 10
14 * 4 = 56
14 / 4 = 3.5
14 div 4 = 3
14 mod 4 = 2
Question 5:
a) Solve the following questions from the Discrete Math zyBook:
1. Exercise 1.12.2, sections b, e
2. Exercise 1.12.3, section c
3. Exercise 1.12.5, sections c, d
b) Solve the following questions from the Discrete Math zyBook:
1. Exercise 1.13.3, section b
2. Exercise 1.13.5, sections d, e
Question 6:
Solve Exercise 2.4.1, section d; Exercise 2.4.3, section b, from the Discrete Math zyBook:
Question 7:
Solve Exercise 2.5.1, section d; Exercise 2.5.4, sections a, b; Exercise 2.5.5, section c, from the Discrete Math zyBook:
Question 8:
Solve Exercise 2.6.6, sections c, d, from the Discrete Math zyBook:
Question 9:
Solve Exercise 2.7.2, section b, from the Discrete Math zyBook:

More products