homework3 - Programming Using C Homework 3 1. Write a...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Programming Using C Homework 3 1. Write a program that computes the histogram of an array. A histogram is a count of how many times each value appears in the array. Assume that the array holds integer values from 0 to N. Make N equal to 20 (what’s the size of the array in this case?). Example: Enter length: 10 Enter values: 2 1 2 0 2 3 1 0 11 0 Histogram: 0... 3 1... 2 2... 3 3... 1 4... 0 5... 0 6... 0 7... 0 8... 0 9... 0 10. ..0 11. ..1 12. ..0 ...... 20. .. 0 2. Write a program that finds prime numbers using Eratosthenes’ Sieve. This is an algorithm that works as follows. Assume we wish to determine which numbers between 2 and 100 are prime. Fill an array with 100 1s: initially every number between 2 and 100 is considered prime. Consider 2: it is prime, so cross out every second number (4, 6, 8, etc.) (set to 0 the corresponding array entry). Then come back to the beginning of the array and move (from 2) on to the next prime number, the next one not crossed out: 3. Cross out every third number: 6, 9, 12, etc. Continue
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

homework3 - Programming Using C Homework 3 1. Write a...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online