⯈Algorithm and its Characteristics
⯈Elementary Problems
- Addition of two numbers
- Calculate area and circumference of circle
- Calculate area of triangle
- Calculate simple interest
- Calculate slope and distance between two points
- Convert length in feet to inches
- Weighted score in exam
- Convert temperature in degree Celsius to Fahrenheit
- Swap two numbers
- Swap two numbers without using extra variable
- Overview of C Programming Language
- Getting started with C Programming Language
- Keywords
- Identifiers
- Constants
- Operators
- Expression Evaluation
- Mathematical expression to C equivalent expressions
- Datatypes
- Variables
- Integer representation in C
- Character representation in C
- Type conversion in C
- sizeof operator
- Comments
- Mathematical Functions
- input output statements
- width specifiers in C
- structure of a C program
- header files
- Compilation process of a C program
- Types of initializations.
⯈Basic C Programs
- C program to add two numbers
- C program to find area and circumference of circle
- C program to swap two numbers
- C program to swap two numbers without using extra variable
- C program to swap two numbers using bitwise XOR
- C program to convert temperature in Celsius to Fahrenheit
- C program to calculate gross salary of an employee
- C program to count number of digits in a positive integer
- C program to count number of digits in binary representation
- C program to count number of digits in base ‘K’
- C program to convert kilometer to meter, feet, inches and centimeters
- C program to find first and last digit of a number
- C program to find minimum number of currency denominations
- C program to convert cartesian coordinates to polar coordinates
- C program to find distance between two places on earth in nautical miles
- C program to find slope and distance between two points
- C program to add 1 to the number using ‘+’ operator
- C program to find maximum of two numbers using ternary operator
- C program to find maximum of three numbers using ternary operator
- C program to find kth bit of a number
- C program to find last four bits of a byte
- C Program to reset right most set bit of a number
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:
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