COMP1721 - Higher Computing 1B

Computing 1B - Week 02 Tutorial Questions

  1. Does the C compiler require that programs be indented or otherwise formatted?

  2. True or false?

  3. What would be the result of compiling and executing this C?

    /* The meaning of life is:
    printf("%d\n", 6*7);
    
    
    

  4. Which of these are legal C variable names and why?

  5. What would be the result of compiling and executing this C?

    
    answer = 42;
    printf("%d\n", answer);
    

  6. What would be the result of compiling and executing this C?

    int x, y;
    x = 15;
    y = x;
    x = 27;
    printf("%d\n", y);
    

  7. What would be the result of compiling and executing this C?

    int x;
    x = "hello world";
    printf("%d\n", x);
    

  8. What would be the result of compiling and executing this C?

    int x;
    x = 42;
    printf("%d\n", X);
    

  9. Write C statements that read two numbers and prints their product. Emulate this behaviour.
    % a.out
    Enter first number: 6
    Enter second number: 7
    The product of 6 and 7 is 42
    

  10. Write C statements that will print 100 times:
    	I must not talk during lectures.
    

  11. Write a Haskell function sigma that given two inputs n and m computes the sum of the integer values from n and m.

    Write C statements to do the same task, i.e. compute the sum of integer values from n to m and print the result.

    Assume that the values n and m are in variable of the same name declared elsewhere.

  12. Write a Haskell script to calculate the n-th tetrahedral number. The n-th tetrahedral number is the sum of the numbers:
            1
            1 2
            1 2 3
            1 2 3 4
    
             .....
    
            1 2 3 4  .... n
    
    The first few tetrahedral numbers are:
            1, 4, 10, 20, 35
    

    Write C statements which print the first 100 tetrahedral numbers.


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