Chapter 4

Making Decisions

Exercises

1.

Type in and run the twelve programs presented in this chapter.

2.

Write a program that takes two numbers from user input and tells the user whether if the first is evenly divisible by the second.

3.

Write a program that takes in two integers and displays the results of dividing the first by the second, to three-decimal-place accuracy.

4.

Write a program that acts as a simple "printing" calculator. The program should allow the user to type in expressions of the form:

number  operator

The following operators should be recognized by the program:

+  -  *  /  S  E

S sets the accumulator to the entered number. E tells the program to end execution.

5.

Program 4.9 reverses the digits of an integer. Modify it so it works correctly with negative numbers.

6.

Program 5.10 has several inefficiencies. The program should not check for even numbers; it also shouldn't continue to check divisors if the current number is already shown to be divisible by a smaller number. Fix these inefficiences in the program.

results matching ""

    No results matching ""