You are on page 1of 3

REVIEW ON COMPUTER PROGRAMMING

Objectives
1. Review the elements of computer programming with emphasis on
good programming principles.
2. Adapt a systematic method of developing computer programs.

COMPUTER PROGRAMMING
A computer requires a program to do any useful work. Programming
languages are used to write computer program.
Computer Program is a set of instructions in a programming language
intended to be executed on a computer to perform a task. Computer
programming involves much more than simply writing a list of instructions.
Problem solving is a crucial component of programming and requires a good deal
of preplanning. Before writing a program to solve a particular problem, you must
consider carefully all aspects of the problem and then develop and organize its
solution.

Computer Problems
1. Write a program that reads in two integers and then outputs their sum,
difference, and product.

2. A Celsius (centigrade) temperature (C) can be converted to an equivalent


9
Fahrenheit temperature (F) according to the formula F = C + 32 . Write a
5
program that reads in a Celsius temperature and then outputs the equivalent
Fahrenheit temperature.

3. (CP) The relationship between the sides (a,b) of a right triangle and the
hypotenuse (h) is given by the Pythagorean formula a2 + b2 = h2. Write a
program that reads in the lengths of the two sides of a right triangle and
computes the hypotenuse of the triangle.

4. (CP) The area of a triangle whose sides are a, b, and c can be computed by
the formula A = s(s − a)(s − b)(s − c ) where s=(a + b + c)/2. Write a program
that reads in the lengths of the three sides of a triangle and outputs the area
of the triangle.

1
Using Conditional Statements
5. (CP) Write a program that gives the user the choice of computing the area of
any of the following: a circle, a square, a rectangle, or a triangle. The program
should include a loop to allow the user to perform as many calculations as
desired. Use a procedure for each of the different kinds of calculations.

Using Repetitive Statement


6. (CP) Write a program to calculate the sum: 1 + 4 + 7 +  + 100 .

1 1 1
7. Write a program to calculate the sum: 1 + + ++ where Terms is
2 3 Terms
specified by the user. This sum is called harmonic series.

8. (CP) Write a program to list the numbers from 0 to 25, their squares, square
roots, fourth power, and fourth root. The output should be in a neat five-
column format.

9. (CP) Write a program that reads in a number N and then outputs the sum of
the squares of the numbers from 1 to N. If the input is 3, for example, the
output should be 14, because 12 + 22 + 32 = 1 + 4 + 9 = 14. The program
should allow the user to repeat this calculation as often as desired.

10. (CP) Write a program to compute the factorial of a number (N!). For example,
3! = 1 x 2 x 3 = 6. By convention, 0! is set equal to 1.

11. (CP) A perfect number is a positive integer that is equal to the sum of all
those positive integers (excluding itself) that divide it evenly. The first perfect
number is 6, because its divisors (excluding itself) are 1, 2, 3, and because 6
= 1 + 2 + 3. Write a program to find the first three perfect numbers (include 6
as one of the three).

12. (CP) Write a program to find all integer solutions to the equation 4x + 3y – 9z
= 5 for values of x, y, and z between 0 and 100.

x2 x3 xn
13. (CP) The value ex can be approximated by the sum 1 + x + + ++ .
2! 3! n!
Write a program that takes a value x as input and outputs this sum for n taken
to be each of the values 1 to 100. The program should repeat the calculation
for new values of x until the user says he or she is through.

Using Procedures or Functions for Subtasks


14. (CP) Write a program that reads in a real number (representing that many
inches) and then outputs the area of a square with sides of that length and
the area of a circle with a diameter of that length. Use two procedures to
compute the two areas.

2
15. Write a procedure that has two formal parameters, one for the radius of a
circle and one for the circumference. Given a radius, the procedure computes
the circumference of the circle and stores the answer in the parameter for the
circumference. Embed this in a program to compute the circumference of a
circle.

Using Arrays
16. CP) Write a program that reads 10 integers into an array, computes the
average, largest, and smallest numbers in the array.

17. (CP) Write a program that allows the user to type in up to 10 positive numbers
and then echoes back the numbers typed in but in reverse order.

18. (CP) Write a program that reads in an m by n matrix (m row by n column),


then reads in an n by p matrix (n row by p column), and then computes the
product matrix and displays the two matrices as well as their product matrix
on the screen.

You might also like