Week 02 Tutorial Questions

  1. Have you got any achievements yet? Are there any that you want to get done this week?
  2. Variables

  3. What are the types of variables that we've seen so far and what do they represent?
  4. What is the difference between a variable and a constant?
  5. What is the difference between declaring variable and using #define?
  6. Program Flow

  7. A leap year is a year that has 366 days instead of 365. There is a leap year every year divisible by four except for years which are both divisible by 100 and not divisible by 400.

    For more detail information of leap years see: Leap Year

    Draw a simple flow chart showing the branches of possibilities to decide if a year is a Leap Year.

    For some humourous information about flow charts see: Flow Charts (xkcd).

    Can you then write some simple code using if/else statements in C that decides if a year is a Leap Year? (hint: modulus is a useful way to decide whether a number is divisible by another) This code question will be continued in this week's lab, so try to remember or keep a copy/photo of the diagram and code you've written.

  8. if Statements

  9. What is the syntax of C if statements? What is the role of if statements in programs?
  10. C Operators

  11. The value of C  arithmetic operations depends on the types of the operand. If the types of the operands differ, C automatically converts the types as appropriate.

    Determine the value of each expression and sub-expression:

    • 1 / 2 * 500
    • 1 / 2.0 * 500
    • (17 / 5) * 5 + (17 % 5)
    • (12 - 17) % 6 - 4
  12. The and (&&) and or (||) operators can be used to combine multiple statments into one (such as the statements created in the leap year activity). Write either a true or false statement about this dog and share with the class. Are your classmates' statments true or false?

    For example:

    • The dog is pink || blue
    • The dog is pink && blue
    A yellow, orange, and pink dog (Source: Jeffree Star Cosmetics, 2012)

    You may also wish to use the "not" operator (!) to make your statements more interesting, for example:

    • The dog is pink || !blue
    • The dog is pink && !blue
  13. scanf()

  14. scanf() and printf() are similar functions.

    printf(): print to the terminal

    scanf(): scan in from the terminal

    Fill in the following table with the correct syntax to print out a variable called a with value 12/ scan in a variable called a.

    printf() scanf()
    int a
    printf( , );
    int a
    scanf( , );
  15. Write a program rectangle_area.c that scans in 2 integers which are the side-length of a rectangle, and then prints the area of the rectangle.

  16. Revision questions

    The remaining tutorial questions are primarily intended for revision - either this week or later in session.

    Your tutor may still choose to cover some of the questions time permitting.