Homework Assignment 5 Solutions

Solutions:

  1. Heron.C: Given a triangle with edge lengths a, b, c, the area of the triangle is given by:
        area = square-root( s (s-a) (s-b) (s-c) )
    
    where s is the semi-perimeter:
        s = (a + b + c ) / 2
    
    Write a program which prompts for and inputs the 3 side lengths of a triangle, and uses Heron's formula to compute the area.
    Solution

  2. Euclidean.C: Write the program Euclidean.C which accepts two integers called i and j and finds the greatest common divisor of the two. This is what they would each have to be divided by to place i/j in reduced form. Check that i is not negative and j is neither negative nor zero, and exit with a message to the user if this is not true. For example:
    Enter integer i: 85
    Enter integer j: 153
    The lowest common divisor is 17
    

    Solution