COMP 1917 Computing 1
Session 2, 2016

Lab - Week 6


There are no assigned lab exercises for this week. You should instead spend the time preparing for the prac exam and/or working on Assignment 1.

You might like to try implementing the Bonus Challenge from last week, or the programs discussed in this week or last week's tutorial. Here are a few examples of the style of questions that might appear on the first Prac Exam:

  1. Write a program which scans an integer n from standard input and then prints all the odd numbers between 1 and n. For example, if n is 7, your program should print
    1
    3
    5
    7
    
  2. Write a program which scans an integer n from standard input and then prints a triangle of size n using the star character '*'. For example, if n is 5, your program should print this:
    *****
    ****
    ***
    **
    *
    
  3. Write a function power_of_two(int k) which takes an ineger k and returns 1 if k is a power of 2, and returns 0 otherwise.

  4. Write a function average(int n, int a[]) which takes an integer n together with an array a[] of n integers, and prints the average of the n items in this array, to two decimal places.

  5. Write a program which continually scans characters from standard input until EOF is reached, then prints the number of times that each of the digits '0' to '9' has occurred in the input.
    Fore example, if the input to your program is
      1232527232B2D232D2J2
    
    your program should print
      0 0
      1 1
      2 10
      3 3
      4 0
      5 1
      6 0
      7 1
      8 0
      9 0