2.9 Implementing Selection and Iteration Algorithms

0 阅读1分钟

1. Exam Points

  • identify if an integer is or is not evenly divisible by another integer
  • identify the individual digits in an integer
  • determine the frequency with which a specific criterion is met
  • determine a minimum or maximum value
  • compute a sum or average
  • Note:
    • Range of the loop control variable (1-19, 1-20, or (1,3,5,7,9))
    • How the loop control variable changes. (++, --, +=2, +=3)
    • Find a number that meets a criterion.
      • (x % 3==1) x = 3n+1
      • (x % 7==2) x = 7n+2

2. Knowledge Points

(1) Implementing Selection and Iteration Algorithms

  • Constructs/structures(构造) widely used in algorithms:
    • Selection
      • if
      • if-else
      • if-else if
    • Iteration/Loop
      • while loops
      • for loops
  • There are standard algorithms to:
      1. identify if an integer is or is not evenly divisible by another integer
      • Ex. identify a multiple of 2 and 7
        image.png
      1. identify the individual digits in an integer
      • Ex. print each digit in a number reversely
        image.png
      1. determine the frequency with which a specific criterion is met
      • Ex. count multiples of 6 between 1 to 30
        image.png
      1. determine a minimum or maximum value
      • Ex. find the minimum among 3 numbers
        image.png
      1. compute a sum or average
      • Ex. calculate the sum of numbers between 10 and 20 image.png

3. Exercises