Homework Assignment 2 Solutions
Solutions:
- Write a program which inputs two integers and prints
the larger of the two.
Solution
- Write a program which inputs three integers and
prints the middle value of the two.
Solution
- 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).
Solution
- 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.
Solution
- 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.
Solution
- 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.
Solution