Exercises

1. Write a function that calculates the average of an array of 10 floating-point values and returns the result.

2. The reduce method from your Fraction class finds the greatest common divisor of the numerator and denominator to reduce the fraction. Modify that method so that it uses the gcd function from Program 13.5 instead. Where do you think you should place the function definition? Are there any benefits to making the function static? Which approach do you think is better, using a gcd function or incorporating the code directly into the method as you did previously? Why?

3. An algorithm known as the Sieve of Erastosthenes can generate prime numbers. The algorithm for this procedure is presented here. Write a program that implements ...

Get Programming in Objective-C, Sixth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.