c201 schedule of first two weeks: review of c101

7
5-1 C201 Schedule of First Two Weeks: Review of C101 Week 1 Functions Array and sorting Week 2 C-String An application

Upload: macaulay-roberts

Post on 30-Dec-2015

18 views

Category:

Documents


0 download

DESCRIPTION

C201 Schedule of First Two Weeks: Review of C101. Week 1 Functions Array and sorting Week 2 C-String An application. Program 1: Determine the day of a week. This is formula to determine the day of a week given the date information - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: C201 Schedule of First Two Weeks: Review of C101

5-1

C201 Schedule of First Two Weeks: Review of C101

Week 1 Functions Array and sorting

Week 2 C-String An application

Page 2: C201 Schedule of First Two Weeks: Review of C101

5-2

Program 1: Determine the day of a weekThis is formula to determine the day of a week given the date

informationW = (k + floor(2.6*m - 0.2) – 2*C + Y + floor(Y/4.0) + floor(C/4.0)) % 7

Where floor() denotes the integer floor function, k is day (1 to 31), m is month (1 = March, ..., 10 = December, 11 = Jan, 12 = Feb), treat

Jan & Feb as months of the preceding year, C is century (1987 has C = 19, 2000 has C=20 except C=19 for Jan &

Feb), Y is year (1987 has Y = 87 except Y = 86 for Jan & Feb), W is week day (0 = Sunday, ..., 6 = Saturday), if W is less than 0, add 7.

Page 3: C201 Schedule of First Two Weeks: Review of C101

5-3

Program 2

Any even number larger than 2 can be expressed as the sum of two prime numbers (Goldbach's conjecture). Write a program that takes input of an even integer number n (larger than or equal to 4) and find two prime numbers p1 and p2, such that n = p1 + p2, and print p1 and p2. For example, 10 = 3 + 7, or 8 = 3 + 5, or 20 = 13 + 7.

Page 4: C201 Schedule of First Two Weeks: Review of C101

5-4

Program 3

Any integer number larger than 5 can be expressed as the sum of three prime numbers (Goldbach's conjecture). Write a program that takes input of an integer number n (larger than or equal to 6) and find three prime numbers p1, p2, and p3 such that n = p1 + p2 +p3, and print p1, p2, and p3. For example, 6 = 2 + 2 + 2, or 8 = 3 + 2 + 3, 11 = 3 + 3 + 5

Page 5: C201 Schedule of First Two Weeks: Review of C101

5-5

Array in C++

Size and index Search an array Sort an array

Page 6: C201 Schedule of First Two Weeks: Review of C101

5-6

C-String

The ending mark: the ‘\0’character C-String functions

strlen() strcmp() Strcpy() Strcat()

Implementations

Page 7: C201 Schedule of First Two Weeks: Review of C101

An Application Write a program that asks a user to enter

his/her first name, year of birth, and weight (in pounds) in one line separated with spaces. The program should show if the user is overweight using the following formula

5-7

Age Weight Result

≤ than 5≥ 98.5 Overweight

< 98.5 Can not tell

> 5≥ 198.5 Overweight

<198.5 Can not tell