Class Notes (836,362)
United States (324,474)
ECE 15 (13)
Lecture 6

# Week 6.docx

3 Pages
37 Views

Department
Electrical & Computer Engineer
Course
ECE 15
Professor
Alon Orlitsky
Semester
Fall

Description
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 2. Arrays 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 not prime. 2. sieve.c a. prime[n] represents n b. we are going to decrease the numbers that are checked by sqrt(n). c. Assume all are prime by setting all array elements as 1 (true) 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). iii. print_string.c 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
More Less

Related notes for ECE 15
Me

OR

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Join to view

OR

By registering, I agree to the Terms and Privacy Policies
Just a few more details

So we can recommend you notes for your school.