Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Jonathan F.

Quiles
II – BSIT – D
Data Structures and Algorithms
Assignment # 2:
➢ Design an algorithm for the following problems using Pseudocode and
Flowcharts.
➢ Turn-in all your answers using MS Word or clear pictures of hand-written
answers.

1.Show the algorithm for computing the velocity of the car. Having the following inputs:

• D1 - the starting point


• D2 - the ending point
• T - Time interval to reach D2
• V = (D2 - D1) / T

START

PSEUDOCODE:
Input D1, D2,
and T;
START
-Input the value of D1, D2, and T.
Compute the
Velocity -calculate the velocity using the formula.

V= (D2-D1)/T -Velocity = (D2-D1)/T


-Display the total velocity of the car.

Display The END


velocity of the
car.

END
2. Show the algorithm for computing the density of a given square. Use the following as
your inputs:

• M - Mass of the object


• V - Volume of the square
• D=M/V - Density of the object

START

PSEUDOCODE:

Input M, and START


V;
-Input the value of M, and T
-calculate the density of the given square
Compute the
Density using the formula.

D = M/V -Density=M/V
-Display the total density of the given

Display The square.


Density of the
given square. END

END
3. Show the algorithms for computing the greatest common divisor of two nonnegative
integers p and q as follows:

• If q is 0, the answer is p.
• If not, divide p by q and take the remainder r. The answer is the greatest
common divisor of p and q.

START

PSEUDOCODE:

Input p, and START


q; - Input value p, q;
- If q=0, the answer is p.
- But if q≠0 divide the p/q and take the
The reminder.
NO
If - mod p/q = r
q=o? - If q is equal 0
mod p/q = r
- Display the answer is p.

YES END

Display “ The
answer is p”

END

You might also like