GET EDUCATE

Contents
Basics of C Programming

⯈Basic C Programs

Algorithm and Flowchart to calculate slope and distance between two points

To calculate the slope and distance between two points, we need input as two points. Let the two points on a 2-D plane be A(x1, y1) and B(x2, y2).

Reading the input:

Read point A as x1, y1

Read point B as x2, y2

slope and distance is calculating using following formulae:

distance (d) = √(x2-x1)² + (y2-y1)²

slope (m) = (y2-y1) / (x2-x1) 

Algorithm for slope and distance is as follows:

Algorithm:

Name of algorithm: Calculate slope and distance between two points.

Step 1: Start

Step 2: Read point A as x1, y1

Step 3: Read point B as x2, y2

Step 4: m = (y2-y1)/(x2-x1) [Calculate slope]

Step 5: d = √(x2-x1)² + (y2-y1)² [Calculate distance]

Step 6: Display d and m

Step 7: Stop

Flowchart:

Flowchart for slope and distance between two points

Tracing:

In Step 2 and 3, we read point A and B.

Let A = (2, 3) and B = (3 , 2), x1 = 2, y1 = 3, x2 = 3, y2 = 2

d = √(x2-x1)² + (y2-y1)²

  = √(3-2)² + (2-3)²

 = 1.414

 (m) = (y2-y1) / (x2-x1) 

       = (2-3)/(3-2)

      = -1

Displays 1.414 and 1

Scroll to Top