COMP 1917 Computing 1
Session 2, 2016

Tutorial - Week 12


Presentation Topic for Week 12

Explain Type Conversion in C. In what situations does type conversion occur?


  1. Write a C program, thousand.c which when run creates a file named "1000.txt" containing the first 1000 integers, one per line.

  2. Write a C program, numbers.c which generalizes the program in the previous exercise. It should take 3 arguments. The first & second arguments will specify the range of integers to be placed in the file. The third argument will specify the file to be created.
    ./numbers 40 42 1000.txt
    cat 1000.txt
    40
    41
    42
    
  3. Write a program, head.c, which given a filename as argument prints the first 10 lines of the file. If the file has less than 10 lines the entire file should be printed.

  4. Write a function that recursively sums all the elements of an array.

  5. Write a recursive function to find the maximum element in an array.

  6. Write a recursive function int length(List l) to calculate the length of a linked list

  7. In previous lab you had to implement a function that prints a list in reverse order. Discuss how you can achieve that task with recursion.

  8. Write a recursive function int search(List l, int val) that returns 1 if val is in the linked list and 0 otherwise.

  9. What are some advantages and disadvantages of using recursion to solve a task?

Presentation Topic for Week 13

For many of you the next step will be taking COMP1927(COMP1521???) where you will learn about data structures and some well known algorithms. One of the crucial concepts in that course is complexity. Explain to the rest of the class what is "big O notation" and give example of programs running in O(1), O(n) and O(n^2).