- 2067 Asar · 5+5 marks
Algorithm and flowchart: distance between points
Short answer
Read coordinates; if any is zero, prompt re‑entry. Then compute D² = (x2 - x1)² + (y2 - y1)² and distance D = √(D²). Print D.
Write an algorithm and flowchart of the distance between two points (x1, y1) and (x2, y2), governed by formula D² = (x2 - x1)² + (y2 - y1)². Where x1, x2, y1, y2 are given by user, but should not be zero.
Since the coordinates must not be zero, the input is checked and read again if any value is zero.
Algorithm
- Start
- Read
x1,y1,x2,y2 - If any of
x1,y1,x2,y2is 0, print "Values must not be zero" and go to step 2 - Calculate
D2 = (x2 - x1)^2 + (y2 - y1)^2 - Calculate
D = sqrt(D2) - Print
D - Stop
Flowchart
( Start )
|
+------>|
| v
| / Read x1,y1,x2,y2 /
| |
| < Any value = 0 ? >--No--+
| | Yes |
| / Print "Values must |
+--- not be zero" / |
v
[ D2 = (x2-x1)^2 + (y2-y1)^2 ]
|
[ D = sqrt(D2) ]
|
/ Print D /
|
( Stop )
Example: (1, 2) and (4, 6) give D2 = 9 + 16 = 25, so D = 5.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Algorithm for numbers divisible by 9 not 6 · Computer Programming, chapter 2
- Algorithm and flowchart help; Armstrong flowchart · Computer Programming, chapter 2
- Algorithm and flowchart for largest · Computer Programming, chapter 2
- Algorithm and flowchart: quadratic roots · Computer Programming, chapter 2
- Two-mass system X1/F, X2/F with F-V analogy · Control Systems, chapter 2 · asked 3×
- Free body diagram and X1/F, X2/F of two-mass system · Control Systems, chapter 2
- Practical factors in sampling; sampling interval for X1(t)X2(t) · Communication Systems, chapter 4
- Find x3[n] from X3=X1X2, x1 5-point, x2 4-point · Digital Signal Analysis and Processing, chapter 7 · asked 3×