1. Exam Problem Types
a. Find syntax errors, run-time (crash,hang) errors, or output
b. Some of: what program does/correct mistakes/determine result
c. Write program
a. Eratosthenes Sieve: For determining if numbers are prime
i. First, pretend that all the integers in the range 2, 3, … N are prime. Then
proceed as follows: (ex: with numbers 1 – 10)
1. 2 is a prime, marks all multiples of 2 as not prime
2. 3 is prime, mark all multiples of 3 as no prime
3. 4 was already marked as not prime, so skip
4. 5 is prime, mark all multiples of 5 as not prime
5. After, all the numbers that remain unmarked must be prime
ii. The program:
1. Integers are represented as an array, 1 indicates prime, 0 indicates
a. prime[n] represents n
b. we are going to decrease the numbers that are checked by
c. Assume all are prime by setting all array elements as 1
d. prime[i*p] declares all multiples of p as not prime
e. i <= n/p further decreases the amount of numbers that
need to be checked.
3. String Arrays
a. String Delimiter
i. Ex: How does printf know when to stop printing when printing a string
array? (for example printing a string array of length 50, but only “yes” in
is inputted, so the word had a shorter length than the string array) ii. Strings are stored with’/0’at end of the declaration of elements, which is
represented with a “0” in theASCII table.
1. printf will stop reading once it encounters this character (0).
1. if “scanf” scans in terms of %s (meaning it will read an entire
string of characters at once) it will stop reading once there is a
space in the string of characters.
b. With copying numbers and characters, you can just set var1=var2. However,
this does not work for strings, because you must copy each element of the array.
Thus, you must c