Algorithm
The algorithm is a step–by–step procedure that is helpful in solving a problem. If it is written in English-like
sentences then, it is called PSEUDO CODE. It is a formula or a set of steps that solves a particular problem
for a specified problem. Each step in the algorithm must be specified clearly.
A programming algorithm is a process or formula for solving a problem. It involves a sequence of specified
actions that describe how to perform a task, which the computer executes consistently. An algorithm follows a
procedure consisting of inputs and produces a result, known as the output. There are some basics steps to
make an algorithm:
1. Start – Start the algorithm
2. Input – Take the input for values in which the algorithm will execute.
3. Conditions – Perform some conditions on the inputs to get the desired output.
4. Output – Printing the outputs.
5. End – End the execution.
The Algorithm for finding the average of three numbers is as follows: It reads three numbers, calculates their
average and sum, and then prints the average value. It involves basic arithmetic operations and simple
input/output steps.
Start
Read 3 numbers a,b,c
Compute sum = a+b+c
Compute average = sum/3
Print average value
Stop
Any good algorithm must have following characteristics
1. Input: Specify and require input
2. Output: Solution of any problem
3. Definite: Solution must be clearly defined
4. Effective
5. Finite: Steps must be finite
6. Correct: Correct output must be generated
Advantages of Algorithms
1. It is the way to sole a problem step-wise so it is easy to understand.
2. It uses definite procedure.
3. It is not dependent with any programming language.
4. Each step has it own meaning so it is easy to debug
Disadvantage of Algorithms:
1. It is time consuming
2. Difficult to show branching and looping statement
3. Large problems are difficult to implement
To solve logical and numerical problems in C, you can follow these steps:
1. Identify the problem: Clearly define the problem
2. Generate solutions: Think of all possible solutions
3. Evaluate alternatives: Remove any solutions that aren't desired
4. Choose a solution: Select the best solution
5. Plan an algorithm: Use tools like pseudocode or IPO charts to plan the algorithm
6. Implement the solution: Use C code to implement the algorithm
7. Evaluate the result: Check the results of your solution
Representation of algorithm:-
Algorithms can be represented in many ways, including:
1.Flow chart
2. pseudocode
Flowchart:
The solution of any problem in picture form is called flowchart. It is the one of the most important technique
to depict an algorithm.
Flowchart is a diagrammatic representation of sequence of logical steps of a program.
Flowcharts use simple geometric shapes to depict processes and arrows to show
relationships and process/data flow.
Flowchart Symbols
Here is a chart for some of the common symbols used in drawing flowcharts.
Symbol Symbol Name Purpose
Used at the beginning and end of the algorithm to show start
Start/Stop
and end of the program.
Process Indicates processes like mathematical operations.
Input/ Output Used for denoting program inputs and outputs.
Stands for decision statements in a program, where answer is
Decision
usually Yes or No.
Arrow Shows relationships between different shapes.
Connects two or more parts of a flowchart, which are on the
On-page Connector
same page.
Connects two parts of a flowchart which are spread over
Off-page Connector
different pages.
Advantage of Flowchart:
1. Easier to understand
2. Helps to understand logic of problem
3. Easy to draw flowchart in any software like MS-Word
4. Complex problem can be represent using less symbols
5. It is the way to documenting any problem
6. Helps in debugging process
Disadvantage of Flowchart:
1. For any change, Flowchart have to redrawn
2. Showing many looping and branching become complex
3. Modification of flowchart is time consuming
Example:- Draw a flowchart to print the input number 5 times.
Algorithm:
1. Start
2. Input number a
3. Now initialise c = 1
4. Now we check the condition if c <= 5, goto step 5 else, goto step 7.
5. Print a
6. c = c + 1 and goto step 4
7. Stop
FlowChart:
A Pseudocode is defined as a step-by-step description of an algorithm. Pseudocode does not
use any programming language in its representation instead it uses the simple English
language text as it is intended for human understanding rather than machine reading.
Pseudocode is the intermediate state between an idea and its implementation(code) in a high-
level language.
What is the need for Pseudocode
Pseudocode is an important part of designing an algorithm, it helps the programmer in planning
the solution to the problem as well as the reader in understanding the approach to the problem.
Pseudocode is an intermediate state between algorithm and program that plays supports the
transition of the algorithm into the program.
Pseudocode is an intermediate state between algorithm and program
How to write Pseudocode?
Before writing the pseudocode of any algorithm the following points must be kept in mind.
Organize the sequence of tasks and write the pseudocode accordingly.
At first, establishes the main goal or the aim. Example:
This program will print first N numbers of Fibonacci series.
Use standard programming structures such as if-else, for, while, and cases the way we use
them in programming. Indent the statements if-else, for, while loops as they are indented in
a program, it helps to comprehend the decision control and execution mechanism. It also
improves readability to a great extent. Example:
IF “1”
print response
“I AM CASE 1”
IF “2”
print response
“I AM CASE 2”
C programming language simply translates the plain language description of the program logic
into C syntax to construct pseudo-code. The C programming language directly corresponds to the
fundamental programming features found in pseudo-code, such as loops, conditionals,
and function calls.
Example:
Let's consider an example of implementing a simple program that calculates the average of three
numbers using pseudo code in C:
Pseudo code:
1. Start
2. Input three numbers
3. Calculate the sum of the three numbers
4. Divide the sum by 3 to get the average
5. Display the average
6. End