Assignment 8

Assignment 8 - CS 136 Fall 2009 Kate Larson Assignment 8...

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

CS 136 Fall 2009 Kate Larson Assignment 8 Due Tuesday, November 24, 2009, 10pm Language level : C To submit : sieve.c , sieve-driver.c , pattern.c , pattern-driver.c , matrix.c and matrix-driver.c 1. The Sieve of Eratosthenes is a simple algorithm for ﬁnding all prime numbers between 2 and some number n . The algorithm works in the following way. First, cross out all numbers that are greater than 2 which are divisible by 2 (every second number). Then ﬁnd the smallest number greater than 2 which has not been crossed out. In this case, it will be 3. Cross out all numbers that are greater than 3 which are divisible by 3. Then ﬁnd the smallest number greater than 3 that has not been crossed out (in this case 5) and cross out all remaining numbers that are greater than 5 and divisible by 5. Continue this procedure until you have crossed out all numbers divisible by b n c . The numbers remaining are all prime. Write a C function void sieve( int A[], int n) where integer array A is of size at least n + 1 and which mutates A so that for 2 i n , A [ i ] has value 1 if i is prime and 0 otherwise. To submit: sieve.c and sieve-driver.c 2. Finding a pattern is a problem that arises in many situations, ranging from text editing pro- grams to analyzing DNA sequences. In this question you will implement a simple function that determines the number of times a particular pattern appears. Let

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.

This note was uploaded on 10/21/2010 for the course CS 136 taught by Professor Becker during the Fall '08 term at Waterloo.

Page1 / 3

Assignment 8 - CS 136 Fall 2009 Kate Larson Assignment 8...

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

View Full Document
Ask a homework question - tutors are online