Algorithm _ Flowchart_Notes(Part-1) (1)
Algorithm _ Flowchart_Notes(Part-1) (1)
FLOW CHART
Introduction
Problem Solving
Algorithm
Examples of Algorithm
Properties of an Algorithm
Flow Chart
Flow Chart Symbols
Some Flowchart Examples
Advantages of Flowcharts
1. Problem Definition
This is the formal definition of task
In this stage following points are important:-
1. Definition of input and output
2. Identify variables
3. Identify different variables
4. Check whether formula is required
2. Program design
In this stage write steps to solve the problem
i.e. either write algorithm or draw flow chart
This step consist of planning the flow of the program
It will guide the actual coding of the program.
3. Coding
This is the step where process of transferring the program design into computer
language.
This step contains:-
i) Use of variables instead of actual data
ii) Use meaningful names of variables
iii) Keep variable names distinct
iv)Avoid complex instructions
v) Give importance to simplicity
4. Debugging
This is the step of correction of programming errors.
It is referred as verification i.e. ensure that the program does what the programmer
want
Some common errors are:-
i) Failure to initialize variables
ii) Failure to handle condition which can cause endless iterations of code
5. Testing
It refers to validation of problem
It includes running the program, testing program for different input values, checking the
output & if any error is there again correcting the errors.
6. Documentation
It is very important step
In the documentation part those who use software can understand it & modify it
whenever needed.
The documentation consist of :
i) Problem definition
ii) flowchart or algorithm
iii) The form of input and output data
iv)Description of files used
v) Program code
Algorithm:
Step1: Start
Step 2:Read/Input the Radius r of the Circle
Step 3: Area = PI*r*r // calculation of area
Step 4: Print Area
Step 5 : Stop
Problem2: Write an algorithm to read two numbers and find their sum.
Algorithm:
Step1: Start
Step2: Read/input the first num1.
Step3: Read/input the second num2.
Step4: Sum =num1+num2 // calculation of sum
Step5: Print Sum
Step6: End
Problem3: Write an algorithm to read two float numbers and find their division.
Inputs to the algorithm:
First num1.
Second num2.
Expected output:
division of the two float numbers.
Algorithm:
Step1: Start
Step2: Read/input the first num1.
Step3: Read/input the second num2.
Step4: Initialize Div (of double type)=0
Step5: Div=num1/num2 // calculation of division
Step5: Print Div
Step6: End
Problem 6: Write an algorithm and program for the use of arithmetic Operators In C++.
(+,-,/,*,%)
• Input:
First num1.
Second num2.
• Output: Use of arithmetic Operators
Control Structures:-
There are three ways in which steps of algorithm carried out:
Sequential Control Structure
Conditional Control Structure
Iterative/Looping Control Structure
written.
A condition is any variable or expression that returns Boolean value(i.e. True or False)
When the condition is associated with a statement that is true then respective
statements will be executed.
Algorithm:
Step1: Start
Step 2:Read integer numbers a, b
Step 3 : initialize max=0
Step 4 : If (a>b) Then
max = a
[End of If ]
Step 5 : Print “ Maximum value = ” max
Step 6 : Stop
Problem 2:-
Write an algorithm to check number is even or not?
Inputs to the algorithm:
Integer number
Expected output:
Number is even or not
Algorithm:
Step1: Start
Step 2:PRINT "Enter the Number"
Step 3: Read integer number num
Step 4: If (num % 2 == 0 )Then
PRINT "Number is Even“
[ End of If ]
Step 5 : Stop
Problem 1:-
Write an algorithm to find smaller of two numbers
Inputs to the algorithm:
First num1.
Second num2.
Expected output:
Smaller number from two numbers
Algorithm:
Step1: Start
Step 2:Read integer numbers a, b
Step 3 : initialize min=0
Step 4 : If (a<b) Then
min= a
Else
min=b
[End of If ]
Step 5 : Print “ Minimum value = ” min
Step 6 : Stop
Problem 2:-
Write an algorithm to check number is even or odd?
Inputs to the algorithm:
Integer number
Expected output:
Number is even or odd
Algorithm:
Step1: Start
Step 2:PRINT "Enter the Number"
Step 3: Read integer number num
Step 4: If (num % 2 == 0 )Then
PRINT "Number is Even“
Else
PRINT "Number is Odd“
[ End of If ]
Step 5 : Stop
Problem 3:-
Write an algorithm to check student Pass or Fail?
Inputs to the algorithm:
Percentage Marks
Expected output:
Student declare as Pass or Fail
Algorithm:
Step1: Start
Step 2:PRINT "Enter the Percentage Marks"
Step 3: Read Marks
Step 4: If Marks < 40 Then
Print “Student is Fail”
Else
Print “Student is Pass”
Step 5 : Stop
Problem 4:-
Write an algorithm to check number is divisible by 5 or not
Inputs to the algorithm:
Integer number
Expected output:
Number is divisible by 5 or not
Algorithm:
Step1: Start
Step 2:PRINT "Enter the Number"
Step 3: Read integer number num
Step 4: If (num % 5 == 0 )Then
PRINT "Number is divisible by 5“
Else
PRINT "Number is not divisible by 5“
[ End of If ]
Step 8 : Stop
If condition(1), then:
[module A1]
else if condition(2), then:
[module A2]
:
:
else if condition(n), then:
[module An]
else :
[module B]
[End of If structure]
Algorithm:
Step1: Start
Step 2:Read integer numbers a, b ,c
Step 3 : initialize max=0
Step 4 :If (a>b) Then
If (a>c) Then
max = a
Else
max=c
Else
If (b>c) Then
max = b
Else
max =c
Step 5 : Print “ Maximum value = ” max
Step 6 : Stop
Problem :- 2
Write an algorithm to find Maximum value from three numbers by using and operator
Inputs to the algorithm:
First num1.
Second num2.
Third num3
Expected output:
larger number from three numbers
Algorithm:
Step1: Start
Step 2:Read integer numbers a, b ,c
Step 3 : initialize max=0
Step 4 :If (a>b) and (a>c) Then
max = a
Else If ( b>a) and (b>c) Then
max = b
Else
max =c
Step 5 : Print “ Maximum value = ” max
Step 6 : Stop
Problem :- 3
Write an algorithm to find out grade of student
Inputs to the algorithm:
Percentage of student
Expected output:
Grade of student
Algorithm:
Step1: Start
Step 2:Read percentage marks of student
Step 3 :If (percentage >= 90)
print “ Student is having A+ grade” and Go to step 4
Else if (percentage >= 80)
print “ Student is having A grade” and Go to step 4
Else if (percentage >= 70)
print “ Student is having B+ grade” and Go to step 4
Else if (percentage >= 60)
print “ Student is having B grade” and Go to step 4
Else if (percentage >= 50)
print “Student is having C grade” and Go to step 4
Else if (percentage >= 40)
print “Student is having Pass Class” and Go to step 4
Else print “ Student is Fail”
[End of If]
Step 4: Stop
Problem :- 4
Write an algorithm to do arithmetic operations on two numbers depending upon the
choice of operator
Inputs to the algorithm:
Two integer numbers num1 & num2
Operator to perform arithmetic operation
Expected output:
Result of entered arithmetic operator
Algorithm:
Step1: Start
Step 2:Read two integer numbers, a & b
Step 3 : Read operator and store in variable ‘ch’
Step 4: If (ch==‘+’) Then
Print “ Addition of a and b = ” a+b and Goto step 5
Else If (ch==‘-’ ) Then
Print “ Subtraction of a and b = ” a-b and Goto step 5
Else If (ch==‘* ’) Then
Print “ Multilication of a and b = ” a * b and Goto step 5
Else If (ch==‘/ ’) Then
Print “ Division of a and b = ” a / b and Goto step 5
Else if ch==‘%’ Then
Print “ Remainder of a and b = ” a % b and Goto step 5
Else
Print “ Invalid input”
[End of If]
Step 5: stop
Problem :- 5
Write an algorithm for the use of conditional, logical, relational Operators to find
minimum and Maximum value from three numbers
Inputs to the algorithm:
First num1.
Second num2.
Third num3
Expected output:
Smaller & larger number from three numbers
Algorithm:
Step1: Start
Step 2:Read integer numbers a, b ,c
Step 3 : initialize min=0 max=0
Step 4 :If (a>b) and (a>c) Then
max = a
Else if ( b>a) and (b>c) Then
max = b
Else
max =c
[End of If]
Step 5 : If (a<b) and (a<c) Then
min = a
Else if ( b<a) and (b<c) Then
min = b
Else
min=c
[End of If]
Here body of loop i.e. module is executed repeatedly, until the condition is
satisfied.
There must be a statement before the structure
that initialize the condition controlling loop counter.
And one statement which change value of condition counter.
Algorithm:
Step1: Start
Step 2: Read N
Step 3: Initialize I= 1, sum =0
Step 4: Repeat steps 5 and 6 while (I<=N)
Step 5: sum = sum +I
Step 6: Set I= I+1
[End of do …. While]
Step 7: Print sum
Step8 : stop
Problem :- 2
Write an algorithm to print table of number using do……while control structure.
Inputs to the algorithm:
Enter number
Expected output:
Table of number
Step1: Start
Step 2: Initialize I= 1, T= 1
Step 3: Read N
Step 4: Repeat steps 5, 6 and 7 while (I <= 10)
Step 5: T = N * I
Step 6: Print T
Step7 : Set I= I+1
[End of do …. While]
Step 8 : stop