Arithmetic - Exercises

Chapter chap3 section 11

  1. Write a program to read in 3 integers and print their sum.

  2. Write a program to read in two integers and display both the quotient and the remainder when they are divided. How does your computer treat the results of division by a negative number? What happens when you try and divide by zero?

  3. What error message does your compiler give when you write

    x+1=x

    in a program?

  4. Write a program to test the behaviour of your computer system when it processes

    printf("%d %d\n",x++,++x);
    

  5. How do you think the computer will evaluate

    x+=x++

    Try and calculate the value for a particular value of x, then write a program to see what really happens. Do you think any other computer might come up with a different result?

  6. Does

    x-=x

    make any sense? What do you think it means?

  7. How would

    x%y%z

    be evaluated? Write a program to find out what happens.

  8. Write a program to read in two integers and display one as a percentage of the other. Typically your output should look like

    20 is 50% of 40

    assuming that the numbers read in where 20 and 40