Programming With Integers - Exercises

Chapter chap2 section 14

  1. Write a C program to print out the sum of two numbers in the form

    The sum of 3 and 4 was 7

    I.e. display the numbers as well as their sum.

  2. Modify the program of exercise 1 to obtain the two numbers interactively from the user.

  3. By specifying a plus-sign in the scanf() format write a program that will read in simple sums such as

    12+34

    and print the result.

  4. Write a program that declares at least three variables and initialises them to fairly large values. By suitable use of the printf() layout print them out in a neat column.

  5. If the symbol "-" appears immediately after the "%" in a d conversion specification for use by printf() then the displayed number is left-justified within the output field rather than the usual right justification. Write a program to demonstrate this, can you think of any use for this facility ?

  6. If the symbol "+" appears immediately after the "%" in a d conversion specification for use by printf() then the number displayed is always preceded by a sign. Write a program to demonstrate this, can you think of any use for this facility ?