0% found this document useful (0 votes)
80 views

2.basics & Algorithm-Flowchart PDF

This document provides information about computer programs, software, and algorithms. It defines key terms: - A program is a set of instructions that directs a computer to solve a problem. Programming is the process of writing programs. - Software includes computer programs and related data that provide instructions for what a computer should do. Software is classified into system software and application software. - An algorithm is a sequence of steps to solve a problem, while a program implements an algorithm. Algorithms have advantages like facilitating program development and error identification.

Uploaded by

Bhumi Vavadiya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views

2.basics & Algorithm-Flowchart PDF

This document provides information about computer programs, software, and algorithms. It defines key terms: - A program is a set of instructions that directs a computer to solve a problem. Programming is the process of writing programs. - Software includes computer programs and related data that provide instructions for what a computer should do. Software is classified into system software and application software. - An algorithm is a sequence of steps to solve a problem, while a program implements an algorithm. Algorithms have advantages like facilitating program development and error identification.

Uploaded by

Bhumi Vavadiya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

Dr. Balu L.

Parne
Assistant Professor,
CoED, SVNIT Surat.
Program & Programming:
 A program is a set of logically related instructions that is arranged in
a sequence that directs the computer in solving a problem.

 The process of writing a program is called programming.


 Software is a collection of computer programs and related data that
provides the instructions for telling a computer what to do and how
to do it.
 Computer software can be broadly classified into two categories :
 system software
&
 application software
Computer Software
 Software is a set of programs, which is designed to
perform a well-defined function. A program is a sequence
of instructions written to solve a particular problem.

User
Application software

System software

Hardware
Application Software
 Application software is written to enable the computer to solve a
specific data processing task.
 Application software is a program that helps user in accomplishing
specific tasks productively.
 word processors
 Games
 instant messenger, etc.
Applications
System Software's:
 System software is a collection of programs
that interfaces with the hardware.
 System software is a program that is not
directly intended to help accomplishing the
user’s task but supports other application
software.
 Operating Systems
 System Tools (e.g. antivirus, archiving tools,
disk defragmenter)
 Software Development Tools (e.g. compiler,
debugger, integrated development
environment suite).
Programming Language :
 A programming language is composed of a set of
instructions in a language understandable to the
programmer and recognizable by a computer.

 Programming languages can be classified as


(a) High-level language - BASIC, COBOL & FORTRAN
(application programs).
(b) Middle level language - C (application & system
programs).
(c) Low level language – assembly language (system
programs).
Structured Programming:
 Structured programming involves top–down analysis for program
solving, modularization of program structure and organizing
structured code for individual module.
 Top-down analysis breaks the whole problem into smaller logical
tasks and defines the hierarchical link between the tasks.
 Modularization of program structure means making the small
logical tasks into independent program modules that carries out the
desired tasks.
 Structured coding is structured programming which consists of
writing a program that produces a well organized module.
Variables and Constants:
 Most important concept for problem solving
using computers

 All temporary results are stored in terms of variables


 The value of a variable can be changed.
 The value of a constant do not change.

 Where are they stored?


 In main memory.
Variables and Constants…
 How does memory look like (logically)?
 As a list of storage locations, each having a unique address.
 Variables and constants are stored in these storage locations.
 A variable is like a bin
 The contents of the bin is the value of the variable
 The variable name is used to refer to the value of the variable
 A variable is mapped to a location of the memory, called its address
Memory Map:
Address 0
Address 1
Address 2
Address 3
Every variable is mapped to a
Address 4
particular memory address
Address 5
Address 6

Address N-1
Variables in Memory :
Instruction executed Variable X

X = 10 10
T
i X = 20 20
m
e
X=X+1 21

X=X*5 105
Variables in Memory… Variable
Instruction executed
X Y
X = 20 20 ?
T
i Y = 15 20 15
m
e
X=Y+3 18 15

Y=X/6 18 3
Data Types :
 Three common data types used:

 Integer :: can store only whole numbers


 Examples: 25, -56, 1, 0

 Floating-point :: can store numbers with fractional values.


 Examples: 3.14159, 5.0, -12345.345

 Character :: can store a character


 Examples: ‘A’, ‘a’, ‘*’, ‘3’, ‘ ’, ‘+’
Problem solving :
 Step 1:
 Clearly specify the problem to be solved.
 Step 2:
 Draw flowchart or write algorithm.
 Step 3:
 Convert flowchart (algorithm) into program code.
 Step 4:
 Compile the program into object code.
 Step 5:
 Execute the program.
Introduction to Algorithms:
 A typical programming task can be divided into two
phases:
 Problem solving phase
 produce an ordered sequence of steps that describe
solution of problem
 this sequence of steps is called an algorithm
 Implementation phase
 implement the program in some programming language
Why Algorithm is needed?
 Computer Program ?
 Set of instructions to perform some specific task
 Is Program itself a Software ?
 NO, Program is small part of software.
 Software merely comprises of Group of Programs (Source
code),
 Code: refers to statements that are written in any
programming language as machine code or C/C++/JAVA
code.
 Code is some time interchangeably used with program.
Why Algorithm is needed?
 Programming is both tedious and exciting.
 Tedious because like spoken languages programming
languages also have so many demanding rules.
 Exciting because writing program provides the programmer
with the chance to create something new also gives challenges
of solving a problem.
 It is very difficult to write direct programs in any language,
just like you can not start constructing building without the
design of building.
 For constructing a building you need design of building,
similarly for writing a large or good program you need
algorithm.
Algorithms:
 Algorithm can be defined as: “A sequence of activities to
be processed for getting desired output from a given
input.”
 A precise sequence of a limited number of unambiguous,
executable steps that terminates in the form of a solution.
 There may be more than one way to solve a problem, so
there may be more than one algorithm for a problem.
 Before writing an algorithm for a problem, one should find
out what is/are the inputs to the algorithm and what
is/are expected output after running the algorithm.
Algorithm Vs Program:
 A program is an implementation of an algorithm to be run on a
specific computer and operating system.
 An algorithm is more abstract – it does not deal with machine
specific details – think of it as a method to solve a problem.
 What is good algorithm?
Efficient algorithms are good, we generally measure efficiency
of an algorithm on the basis of:
1. Time: algorithm should take minimum time to
execute.
2. Space: algorithm should use less memory.
Algorithm Specifications:
Every algorithm must satisfy the following criteria:
 Input. Zero or more quantities are externally supplied.
 Output. At least one quantity is produced.
 Definiteness. Each instruction must be clear and
unambiguous (Unique meaning).
 Finiteness. An algorithm terminates in a finite number of
steps.
 Effectiveness. Every instruction must be basic enough to
be carried out (means not so complex).
Example of Algorithm:
 Example 1: Write an algorithm to find the sum of two numbers.
 Example 2: Write an algorithm to find the average of 3
numbers.
 Example 3: Write an algorithm to find the largest among given
two numbers.
 Example 4: Write an algorithm to determine a student’s final
grade and indicate whether it is passing or failing. The final
grade is calculated as the average of four marks. To pass the
exam average of four subject must be greater than or equal to
50.
Examples of Algorithm:
 Example1 : Add two numbers.
 Step 1: Start
 Step 2: Read 2 numbers as A and B
 Step 3: Add numbers A and B and store result in C
 Step 4 : Display C
 Step 5: Stop
Examples of Algorithm:
 Example 2 : Average of 3 numbers.
 Step 1: Start
 Step 2: Read the numbers a , b , c
 Step 3: Compute the sum and divide by 3
 Step 4: Store the result in variable d
 Step 5: Print value of d
 Step 6: End
Examples of Algorithm:
 Example 3 : Maximum of 2 numbers.
 Step 1 : Start
 Step 2 : Input A , B
 Step 3 : if A > B then output A
else output B
 Step 4 : Stop
Examples of Algorithm:
 Example 4 : Grade Marks.
Step 1: Start
Step 1: Input M1,M2,M3,M4
Step 2: GRADE  (M1+M2+M3+M4)/4
Step 3: if (GRADE < 50) then
Print “FAIL”
else
Print “PASS”
endif
Step 4: Stop
Advantages of Algorithms:
 It facilitates program development by acting as a design
document or a blue print of a given problem solution.
 The solution can be implemented on a computer system
using any programming language of user’s choice.
 It ensures easy comprehension of a problem solution as
compared to an equivalent computer program.
 It eases identification and removal of logical errors in a
program.
 It facilitates algorithm analysis to find out the most
efficient solution to a given problem.
Disadvantages of Algorithms:
 In large algorithms the flow of program control becomes
difficult to track.
 Algorithms lack visual representation of programming
constructs like flowcharts; thus understanding the logic
becomes relatively difficult.
Introduction to Flowchart
 A flowchart is a visual representation of the sequence of
steps for solving a problem .
 A flowchart is a set of symbols that indicate various
operations in the program.
 A flowchart gives a pictorial representation of an
algorithm.
 It is a symbolic diagram of operations sequence,
dataflow, control flow and processing logic in
information processing.
Why Flowchart is needed?
 A graphical representation of an algorithm, often
used in the design phase of programming to work
out the logical flow of a program.
 Visual way to represent the information flow
 Quick method of showing program flow
 Make our logic more clear
 Help during writing of program
 Make testing and debugging easy
Flowchart: basic symbols
Computation

Input / Output

Decision Box

Start / Stop
Flowchart: basic symbols…
Flow of
control

Connector
Flowchart or Program Constructs:
 Sequence: The order of execution, this typically refers to
the order in which the code will execute. Normally code
executes line by line, so line 1 then 2 then 3 and so on.

 Selection: Selection, like branching, is a method of


controlling the execution sequence, you can create large
control blocks, using if statements testing a condition, or
switch statements evaluating a variable etc. to control
and change the execution of the program depending on
this environment and changing variables.
Flowchart or Program Constructs:
 Iteration (Repetition): Iteration is typically used to refer to
collections and arrays of variables and data. Repeating set of
instruction. Counting from 1 to 10, you are iterating over the
first 10 numbers. for, while, do-while loops will be
implemented for iteration.
Flowchart Constructs:
Flowchart Constructs:
Flowchart Constructs:
Example :
 Example 1: Write an algorithm and draw a flowchart to find
the sum of two numbers.
 Example 2: Write an algorithm and draw a flowchart to find
the average of 3 numbers.
 Example 3: Write an algorithm and draw a flowchart to find
the largest among given two numbers.
 Example 4: Write an algorithm and draw a flowchart to
determine a student’s final grade and indicate whether it is
passing or failing. The final grade is calculated as the average
of four marks. To pass the exam average of four subject must be
greater than or equal to 50.
Examples of Algorithm:
 Example 1 : Add two numbers.
 Step 1: Start
 Step 2: Read 2 numbers as A and B
 Step 3: Add numbers A and B and
store result in C
 Step 4 : Display C
 Step 5: Stop
Examples of Algorithm:
 Example 2 : Average of 3 numbers.
 Step 1: Start
 Step 2: Read the numbers a , b , c
 Step 3: Compute the sum and divide by 3
 Step 4: Store the result in variable d
 Step 5: Print value of d
 Step 6: End
Examples of Algorithm:
 Example 3 : Maximum of 2 numbers.
 Step 1 : Start
 Step 2 : Input A , B
 Step 3 : if A > B then output A
else output B
 Step 4 : Stop
Examples of Algorithm:
 Example 4 : Grade Marks.
Step 1: Start
Step 1: Input M1,M2,M3,M4
Step 2: GRADE  (M1+M2+M3+M4)/4
Step 3: if (GRADE < 50) then
Print “FAIL”
else
Print “PASS”
endif
Step 4: Stop
 Example 4 : Grade
Marks.
Example :
 Example 5: Write an algorithm and draw a flowchart that will
read the two sides of a rectangle and calculate its area.
 Example 6: Write an algorithm and draw a flowchart to
convert the length in feet to centimeter.
 Example 7 : Write an algorithm and draw a flowchart to
converts the input Fahrenheit degree into its Celsius degree
equivalent. Use the formula: C= (5/9)*F-32.
 Example 8: Write an algorithm and draw a flowchart to Find
whether a given number is odd or even.
Examples of Algorithm:
 Example 5 : Area of rectangle.
 Step 1: Start
 Step 2: Read length and width of
a rectangle as L and W.
 Step 3: Compute area and store in A
 Step 4 : Display A
 Step 5: Stop
Examples of Algorithm:
 Example 6 : Foot to CM.
 Step 1: Start
 Step 2: Read length in feet as Lft.
 Step 3: Compute length in centimeter
as Lcm=30*Lft.
 Step 4 : Print / Display Lcm.
 Step 5: Stop
Examples of Algorithm:
 Example 7 : Fahrenheit to Celsius.
 Step 1: Start
 Step 2: Read temperature in Fahrenheit F.
 Step 3: Compute temperature in Celsius
as C = 5/9*(F-32).
 Step 4 : Print / Display C.
 Step 5: Stop
Sum of First n- natural numbers
Thank You…!!!

You might also like