Homework Assignment 2
Assigned: Monday, Jan 29.
Due: Monday, Feb 5.
Read: 3.1, 3.2, 4.1, 4.2.
Do:
3.8.1, 3.8.2, 4.10.1, 4.10.2.
Program:
- Write a program which inputs two integers and prints
the larger of the two.
- Write a program which inputs three integers and prints
the middle value of the two.
Here is the problem broken down into 3 easier steps.
- Step 1: Input i, j, k.
- Step 2: Place i, j, k into integer variables
little, middle, big so that
- Step 3: Print the value of middle.
- Write a program which inputs two integers and prints the largest
multiple of the second which is smaller than the first, and the smallest
multiple of the second which as at least as large as the first.
That is, input n and d, then find i and j such so that
and print (i*d) and (j*d).
What conditions on n and d are necessary for this problem to be solvable?
For extra credit, use if statements to prevent bad inputs.
- Three positive integers a, b, c are a Pythagorean Triple if:
An example Pythagorean Triple is 3, 4, 5. Pythagorean Triples are
the side lengths of rigth triangles and were of interest in ancient
times in order to survey land.
Write a program that inputs three integers, checks that they are
positive and prints whether they are a Pythagorean Triple or not.
- The previous problem is about recognizing Pythagorean Triple. Write
a program which produces Pythagorean Triples.
The program accepts
two odd integers and derives a Triple from them. You will probably
need a hint to solve this problem.
- Write a program that accepts four integers, i, j, k, n and
prints which of the relations is correct:
For this problem, do not use floating point arithmetic. You should
determine the equality or inequality using only integer arithmetic.
Do this problem in 2 steps:
- Assume that i, j, k, n are positive.
- Deal with the troubles of allowing any integer values for i, j, k and n.