cs102 lab5


http://www.maths.nuigalway.ie/~gettrick/teach/cs102/labs/l5.html



  1. Adapt (change) the binary search program
    http://www.maths.nuigalway.ie/~gettrick/teach/cs102/progs/
    http://www.maths.nuigalway.ie/~gettrick/teach/cs102/progs/binsR.py
    so that if there are multiple occurrences of a particular data value, it will find all these occurrences. So, your program (which must be recursive) will print out
    • The position of each occurrence.
    • The total number of occurrences.
    Test your program on the (ordered) list of numbers at http://www.maths.nuigalway.ie/~gettrick/teach/cs102/list.txt, by searching this list for the numbers 42, 211, 332 and 493.
  2. Write a recursive program that calculates, given as input a positive integer n, the sum of all the numbers up to (and including) n.


© NUI, Galway