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 ﬁnds 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
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Summer '08
 Staff
 Array, 10%, 5%, 20%

Click to edit the document details