COMP1721 - Higher Computing 1B

Computing 1B - Week 04 Tutorial Questions

  1. Write a C program which reads a string and prints it, but without any vowels.

    For example:

    % a.out
    Enter a string: The quick brown fox jumped over the lazy dog.
    Th qck brwn fx jmpd vr th lzy dg.
    % a.out
    Enter a string: It was the best of times. It was the worst of times.
    t ws th bst f tms. t ws th wrst f tms.
    

  2. Write a C program which reads lines and writes them out with the characters of each line in reverse order. It should stop when it reaches the end of input.

    For example:

    % a.out
    The quick brown fox jumped over the lazy dog.
    .god yzal eht revo depmuj xof nworb kciuq ehT
    It was the best of times. It was the worst of times.
    .semit fo tsrow eht saw tI .semit fo tseb eht saw tI
    This is the last line.
    .enil tsal eht si sihT
    
    

  3. This question involves simulating the rolling a pair of six-sided dice in C.

    Recall that the function rand() yields a pseudom-random int.

    Write a C program which asks the user how many times to roll a pair of 6 sided dice and prints a tally of all the numbers rolled. Don't output zero tallies. The output from your program should look like this:

    % a.out
    How many times should I roll the dice? 8
    You rolled 4 and 6 = 10
    You rolled 1 and 2 = 3
    You rolled 4 and 6 = 10
    You rolled 6 and 5 = 11
    You rolled 3 and 6 = 9
    You rolled 1 and 2 = 3
    You rolled 5 and 4 = 9
    You rolled 3 and 6 = 9
    2 3s were rolled
    3 9s were rolled
    2 10s were rolled
    1 11s were rolled
    

    Use an array to store the tallies.


Andrew Taylor (andrewt@cse.unsw.edu.au)
Higher Computing 1B, Computer Science & Engineering, UNSW