You are on page 1of 15

Computer Programming

Mechanical Engineering (1st Year 2nd Semester)


Session: 2020 - 2021
Algorithms and Flowcharts

Anirban Mitra
Assistant Professor
Department of Mechanical Engineering
Jadavpur University
Name of Course: Computer Programming
• Year: 1st, Semester: 2nd
• Session: 2020-21
• Syllabus:
▪ Introduction: History of Computing, Evolution of Programming Languages, Compilers, Interpreter
Algorithms and Flowcharts, Structure of a C Program. [33 h]
▪ Expressions : Basic Data Types, Variables, Type Qualifiers, Variable Scopes, Constants, Assignment
Statements, Operators, Operator Precedence, Expression Evaluation, Type Conversion in Expressions,
Type Casting; Console I/O: Reading and Writing different data types [23 h]
▪ Control Statements: Selection Statements (if, switch-case), Loop Statements (for, while, do-while), Jump
Statements (return, goto, break, exit, continue) [23 h]
▪ Arrays and Strings: Single Dimension Arrays, Double Dimension Arrays, Strings [23 h]
▪ Functions: General Form, Function Prototypes, Introduction to Pointer variables, Parameter Passing
Mechanisms, Command Line Arguments [23 h]
▪ File I/O: Introduction to File, File reading and writing [13 h]
▪ Structures, Unions: Structures, Arrays of Structures, Unions [13 h]

Jadavpur 2
University
Introduction
▪ Computer is a wonderful invention, whose importance in material and intellectual progress of
mankind is well recognised in developed as well as developing countries
▪ Computers are being used in almost every field of modern society
▪ A computer can neither think nor take decisions on its own
− Can not decide a method to find solutions
▪ Computer only understands what to do when it is told the problem and how to obtain the solution Communication
to the problem in precise and unambiguous form with Computer –
Programming
▪ Most difficult and important task in programming – not preparation of instructions for the
Languages
computer to solve a given problem
− Systematic and careful analysis of the entire problem and deciding upon an effective
method of solution

Jadavpur 3
University
Introduction
▪ Steps to solve any physical problem utilizing computers:
− Convert the physical problem into a mathematical model (formulate the mathematical equations)
− Select a suitable method to solve the mathematical equations and write down the steps necessary
for obtaining the solution in the form of an Algorithm
− Graphically represent the procedural steps to be executed for solving the given problem (Draw
detailed Flow chart)
− Convert the flow chart into a source program
− Compile and execute the program

Jadavpur 4
University
Introduction

Logic of
problem solution Source Programme Object Programme

Computer Sequence of machine


Algorithm/
Problem Programme in High instructions Output
Flowchart level language (Machine Language)

Compilation Execution
Compiler/Interpreter
System Software
Physical Mathematical
Governing
Problem Model
Equations

Jadavpur 5
University
Algorithm

Jadavpur 6
University
Algorithm
▪ A complete and unambiguous set of computational steps to be followed in a particular sequence
to obtain solution to a given problem

▪ It tells the computer - where to start


what information to read
what operations to be carried out & in which order
what information to be displayed
when to stop

Jadavpur 7
University
Algorithm: Important Features
▪ Important features of an algorithm:
− Finiteness: terminate after a finite no. of steps
− Definiteness: steps must be clearly defined (unambiguous action)
− Input: quantities to be read as input
− Output: quantities to be displayed
− Effectiveness: all operations must be executable (avoid division by 0, -ve no. under root etc.)

Jadavpur 8
University
Flowchart

Jadavpur 9
University
Flowchart
▪ Visual/Graphical representation of the sequential steps of the algorithm required to produce the
solution to a problem

▪ Depicts in a pictorial form


− sequence in which conditions are to be tested
− calculations to be performed (to solve a problem)
▪ Used not only as a problem planning aid but also as documentation of the procedure followed in
solving a problem

Jadavpur 10
University
Shape Name Description
An arrow coming from one symbol and ending at another
Flow Line symbol represents that control passes to the symbol the arrow
points to.

Represented as circles, ovals, or rounded (fillet) rectangles. They


Terminal
usually contain the word “Start” or “End”.

Represented as rectangles. This shape is used to show that


Process
something is performed.

Represented as a diamond (rhombus) showing where a decision


is necessary, commonly a Yes/No question or True/False test.
Decision
The conditional symbol is peculiar in that it has two arrows
coming out of it.

Represented as a parallelogram. Involves receiving data and


Input/Output
displaying processed data.

Loop Repetitive execution (till logical expression is true)


Jadavpur 11
University
Shape Name Description
Represented as a parallelogram. Involves receiving data and
Input/Output
displaying processed data.

Alternative to parallelogram

Input: Symbol specifying quantities which are to be read before processing can
proceed

Output: Specifying quantities which are to be output

Jadavpur 12
University
Example: Algorithm and Flowchart
Write down an algorithm to calculate and print the value of K, where,
100

𝐾 = ෍ 𝐽2
𝐽=1

Jadavpur 13
University
Example: Algorithm and Flowchart
Write down an algorithm to calculate and print the value of K, where,
100

𝐾 = ෍ 𝐽2
𝐽=1

Jadavpur 14
University
THANK YOU

You might also like