0% found this document useful (0 votes)
21 views25 pages

Unit I FlowChart

Uploaded by

tv5874
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views25 pages

Unit I FlowChart

Uploaded by

tv5874
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

School of Computing Science and Engineering

Course Code : E2UC102C Name: Programming for Problem Solving

UNIT I
INTRODUCTION TO COMPUTERS AND
ALGORITHMS

FLOWCHART

Name of the Faculty: Tarachand Verma Program Name:B.Tech(CSE)


Objectives

• Introduction to Flow Chart


• Structures of Flowchart
• Sequence
• Decision
• Repetition
• Case
Introduction to FlowChart

3
Introduction to FlowChart

START

Display message
“How many
hours did you
• A flowchart is a diagram that work?”

depicts the “flow” of a program. Read Hours

• The figure shown here is a Display message

flowchart for the pay-calculating


“How much do
you get paid per
hour?”
program
Read PayRate

Multiply Hours
by PayRate.
Store result in
GrossPay.

Display
GrossPay

END
4
Basic Flowchart Symbols
START Terminal

Display message
“How many
hours did you
work?”

• Terminals Read Hours

• represented by rounded Display message


rectangles “How much do
you get paid per
• indicate a starting or hour?”

ending point
Read PayRate

Multiply Hours
by PayRate.
START Store result in
GrossPay.

Display
GrossPay

END Terminal
END

5
Basic Flowchart Symbols
START

Display message
“How many
hours did you
work?”

• Input/Output Operations Read Hours

• represented by Display message


parallelograms “How much do
you get paid per
Input/Output
Operation
• indicate an input or hour?”

output operation
Read PayRate

Multiply Hours
by PayRate.
Display message Store result in
GrossPay.
“How many
Read Hours
hours did you Display
GrossPay
work?”
END

6
Introduction to Flowchart
START

Display message
“How many
hours did you
work?”

• Processes Read Hours

• represented by rectangles Display message


• indicates a process such as “How much do
you get paid per
a mathematical hour?”

computation or variable
assignment Read PayRate

Multiply Hours
by PayRate.
Process Store result in
Multiply Hours GrossPay.
by PayRate.
Store result in Display
GrossPay
GrossPay.
END

7
Structures of Flowchart

• Sequence
• Decision
• Repetition
• Case

8
Sequence

• A series of actions are performed in sequence


• The pay-calculating example was a sequence flowchart.

9
Decision Structure

• The flowchart segment below shows how a decision structure is expressed in C++
as an if/else statement.

Flowchart C Code

Yes No if (x > y)
x>y? printf(“X is bigger”);
else
printf(“Y is bigger”);
X is Big Y is Big

10
Decision Structure

• The flowchart segment below shows a decision structure with only one action to
perform. It is expressed as an if statement in C++ code.

Flowchart C++ Code

NO YES if (x < y)
x < y? a = x * 2;

Calculate a
as x times 2.

11
Repetition Structure

• The flowchart segment below shows a repetition structure expressed in C++ as a


while loop.

Flowchart C Code

while (x < y)

YES x=x+1;
x<y? Add 1 to x

No

12
Controlling a Repetition Structure

• The action performed by a repetition structure must eventually cause the loop to
terminate. Otherwise, an infinite loop is created.
• In this flowchart segment, x is never changed. Once the loop starts, it will never
end.
• QUESTION: How can this
flowchart be modified so
it is no longer an infinite YES
loop? x < y? Display x

13
Controlling a Repetition Structure

• ANSWER: By adding an action within the repetition that changes the value of x.

YES
x < y? Display x Add 1 to x

14
Case Structure

If years_employed = 2, If years_employed = 3,
bonus is set to 200 bonus is set to 400
If years_employed = 1, CASE If years_employed is
years_employed more than 3, bonus is
bonus is set to 100
set to 800
1 2 3 Other

bonus = 100 bonus = 200 bonus = 400 bonus = 800

15
Connectors

•The “A” connector


indicates that the second START A

flowchart segment begins


where the first segment
ends.

END
A

16
Modules

START
•The position of the module
symbol indicates the point the Read Input.
module is executed.
•A separate flowchart can be Call calc_pay

constructed for the module. function.

Display results.

END

17
Combining Structures

• This flowchart segment


shows two decision
structures combined. NO YES
x > min?

Display “x is NO YES
outside the limits.”
x < max?

Display “x is Display “x is
outside the limits.” within limits.”

18
Review

• What do each of the following symbols represent?

(Answer on next slide)


19
Introduction to FlowChart

• What do each of the following symbols represent?

Decision
Terminal

Input/Output
Operation Connector

Process Module

20
Example- Adding Two Numbers

21
Example- Finding an Item
Example

23
References

• E. Balagurusamy 7th Edition, Programming ANSI C, McGraw-Hill


• Brian W. Kernighan and Dennis M. Ritchie, The C programming Language,
Prentice-Hall in 1988
• Byron Gottfried, Programming with C, Schaum's Outline

Program Name: B.Tech (CSE)

You might also like