Homework Assignment 2 Solutions

Solutions:
  1. Write a program which inputs two integers and prints the larger of the two.
    Solution

  2. Write a program which inputs three integers and prints the middle value of the two.
    Solution

  3. 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 (i*d) < n <= (j*d) and print (i*d) and (j*d).
    Solution

  4. Three positive integers a, b, c are a Pythagorean Triple if: (a*a) + (b*b) = (c*c) 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

  5. 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

  6. Write a program that accepts four integers, i, j, k, n and prints which of the relations is correct: i/j < k/n, or i/j == k/n, or i/j > k/n For this problem, do not use floating point arithmetic. You should determine the equality or inequality using only integer arithmetic.
    Solution