Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "5-1 C201 Schedule of First Two Weeks: Review of C101  Week 1  Functions  Array and sorting  Week 2  C-String  An application."— Presentation transcript:

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

2 5-2 Program 1: Determine the day of a week This is formula to determine the day of a week given the date information W = (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.

3 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.

4 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

5 5-5 Array in C++  Size and index  Search an array  Sort an array

6 5-6 C-String  The ending mark: the ‘\0’character  C-String functions  strlen()  strcmp()  Strcpy()  Strcat()  Implementations

7 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 AgeWeightResult ≤ than 5 ≥ 98.5Overweight < 98.5Can not tell > 5 ≥ 198.5Overweight <198.5Can not tell


Download ppt "5-1 C201 Schedule of First Two Weeks: Review of C101  Week 1  Functions  Array and sorting  Week 2  C-String  An application."

Similar presentations


Ads by Google