⯈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

## Algorithm and its characteristics

An **Algorithm** is a step-by-step procedure to solve a given problem, which has the following characteristics.

**Input:**An algorithm should have zero or more inputs.**Output:**An algorithm should have at least one output.**Finiteness:**An algorithm should have finite number of steps. The algorithm shouldn’t go on repeating for infinite time. If an algorithm runs for an infinite time then we may not get the output, which may fail the 2nd characteristic (output).**Definiteness:**Each step of the algorithm should be clear and precise. There shouldn’t be any ambiguity in carrying out the steps of the algorithm.**Effectiveness:**Each step of the algorithm should terminate in finite amount of time. The algorithm may have finite steps, but say for example the step 2, takes infinite time to complete, the algorithm will never reach to step 3.

There are some algorithms where we have zero inputs, like calculating the value of PI, accurate to 4 decimal places.

An algorithm should produce at least one output, if an algorithm doesn’t provide any output, then there was no point in solving the algorithm.

### Writing an algorithm:

The algorithm should be written in a step-by-step manner. It can be written in a language near to the programming language so that the translation from algorithm to program will be easy.

We will write the algorithm using the:

**Name of algorithm**: says what does the underlying algorithm perform.**Step number**: which indicates what step we are carrying out.**Explanatory comments**: which says what does the following step will perform. These are written in square brackets. These are optional.

#### Example: Write an Algorithm to add two numbers.

**Algorithm Name:** Algorithm to add two numbers.

Step 1: Start

Step 2: Read two numbers as A and B.

Step 3: Sum = A+B [Adding two numbers]

Step 4: Display Sum.

Step 5: Stop [or End].

We will discuss in the next sections after introduction to flowchart on how we write the algorithms using the above steps.