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

CSE101 - Lec 2 (Algorithm and Flowchart)

Uploaded by

Pawan Kumar
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)
62 views

CSE101 - Lec 2 (Algorithm and Flowchart)

Uploaded by

Pawan Kumar
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/ 33

CSE101-Lec#2

Structured Programming Using Algorithm and Flowchart(or


Program development tools)
Outline
• Structured programming using
• Algorithm and
• Flowchart
or
• Program development tools

©LPU CSE101 C Programming


Program Development Tools
• Algorithm
• Flowchart

©LPU CSE101 C Programming


Algorithm
• Algorithm is defined as “ the finite set of steps,
which provide a chain of action for solving a
problem”
• It is step by step solution to given problem.
• Well organized, pre-arranged and defined
textual computational module

©LPU CSE101 C Programming


Characteristics of good Algorithm
1. Correctness - terminates on ALL inputs (even invalid inputs!) and
outputs the correct answer.
2. Simplicity - each step of the algorithm performs one logical step in
solving the problem.
3. Precision - each step of the algorithm is unambiguous in meaning.
4. Comprehensibility - the algorithm is easy to read and understand.
5. Abstraction - presents the solution steps precisely and concisely
without referring to low-level (program code) details.
6. Efficient - Gives results rapidly based on the problem size; does
not waste any space or time.
7. Easy to Implement - relatively easy to translate into a
programming language.

©LPU CSE101 C Programming


Steps to create an Algorithm
1. Identify the Inputs
• What data do I need?
• How will I get the data?
• In what format will the data be?

2. Identify the Outputs


• What outputs do I need to return to the user?
• What format should the outputs take?

©LPU CSE101 C Programming


Steps to create an Algorithm
3. Identify the Processes
• How can I manipulate data to produce
meaningful results?
• Data vs. Information

4. Break the Solution to steps


By breaking the solution to the steps we can
easily understand the logic of program

©LPU CSE101 C Programming


General example of Algorithm
To establish a telephone communication
• Step 1: Dial a phone number
• Step 2: Phone rings at the called party
• Step 3: Caller waits for the response
• Step 4: Called party picks up the phone
• Step 5: Conversation begins between them
• Step 6: After the conversation, both disconnect
the call

©LPU CSE101 C Programming


Algorithm: Add 2 Numbers[Example 1]

Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to
sum.
sum←num1+num2
Step 5: Display sum
Step 6: Stop

©LPU CSE101 C Programming


Algorithm: Calculate area of circle[Example 2]

Step 1: Start
Step 2: Declare variables radius and area.
Step 3: Read value of radius.
Step 4: Apply the expression as specified below
and assign the result in area
area←3.14*radius*radius
Step 5: Display area
Step 6: Stop

©LPU CSE101 C Programming


Algorithm: Swap the values of two variables[Example 3]

Step 1: Start
Step 2: Declare three variables: num1,num2 and temp
Step 3: Read values of num1 and num2
Step 4: Assign the value of num1 in temp
temp ←num1
Step 5: Assign the value of num2 in num1
num1 ←num2
Step 6: Assign the value of temp in num2
num2 ←temp
Step 7: Display swapped values of num1 and num2
Step 8:Stop

©LPU CSE101 C Programming


Practice questions for Algorithms
• Write an algorithm to calculate and display simple interest
and final amount
• Write an algorithm to swap the values of 2 numbers without
using temporary variable
• Write an algorithm to convert temperature from degree
Celsius to degree Fahrenheit and vice versa
• Write an algorithm to multiply, divide and subtract two
numbers and display their individual results
• Write an algorithm to read the prices and quantities of 5
items and display the final amount after applying a discount
of 10 percent
• Write an algorithm to convert distance from km to m and vice
versa
• Write an algorithm to display the areas of triangle, square and
rectangle and display their individual results.

©LPU CSE101 C Programming


Q1
Which of the following characteristic is not
desired in good algorithm?
A. Ambiguity
B. Correctness
C. Simplicity
D. Abstraction

©LPU CSE101 C Programming


Q1
Which of the following characteristic is not
desired in good algorithm?
A. Ambiguity
B. Correctness
C. Simplicity
D. Abstraction

©LPU CSE101 C Programming


Q2
Q2:Algorithm is:
A. Infinite set of steps
B. Pictorial representation
C. Textual Computational solution
D. Actual Code for the solution

©LPU CSE101 C Programming


Q2
Q2:Algorithm is:
A. Infinite set of steps
B. Pictorial representation
C. Textual Computational solution
D. Actual Code for the solution

©LPU CSE101 C Programming


Q3
Q3.Efficient algorithm is one which takes
A. Less time
B. Less space
C. More time and space
D. Both A and B options

©LPU CSE101 C Programming


Q3
Q3.Efficient algorithm is one which takes
A. Less time
B. Less space
C. More time and space
D. Both A and B options

©LPU CSE101 C Programming


Flow Chart
• Flow Chart is pictorial representation of an
algorithm.
• Whatever we have done in algorithm we can
represent it in picture.
• It is easy to understand.
• Shows the flow of the instruction

©LPU CSE101 C Programming


Flow Chart Symbols

©LPU CSE101 C Programming


Flowchart Example 1-Adding 2 numbers

©LPU CSE101 C Programming


Flowchart Example 2-Displaying greatest of 2 numbers

©LPU CSE101 C Programming


Flowchart Example 3-Checking whether a person is
eligible to vote or not

©LPU CSE101 C Programming


Flowchart Example 3-Greatest of 3 numbers

©LPU CSE101 C Programming


Practice questions for flowcharts
Write solutions using RAPTOR and without RAPTOR(Basic conventions)

1) Draw a flowchart to check whether a given


number is even or odd
2) Draw a flowchart to calculate simple interest and
final amount
3) Draw a flowchart to calculate the area of a circle
4) Draw a flowchart to display the roots of a
quadratic equation
5) Draw a flowchart to check whether the given
number is a multiple of 5 or not
6) Draw a flowchart to swap the values of two
variables without the help of temporary variable

©LPU CSE101 C Programming


Q1
Which of the following symbol is used to denote
decision or condition in a flowchart?
A. Oval
B. Rectangle
C. Diamond
D. Small Circle

©LPU CSE101 C Programming


Q1
Which of the following symbol is used to denote
decision or condition in a flowchart?
A. Oval
B. Rectangle
C. Diamond
D. Small Circle

©LPU CSE101 C Programming


Q2
Oval symbol in a flowchart is used to represent
A. Input/Output
B. Decision
C. Connector
D. Start and Stop

©LPU CSE101 C Programming


Q2
Oval symbol in a flowchart is used to represent
A. Input/Output
B. Decision
C. Connector
D. Start and Stop

©LPU CSE101 C Programming


Q3
Which of the following symbol is used to denote
processing part in a flowchart?
A. Oval
B. Rectangle
C. Diamond
D. Parallelogram

©LPU CSE101 C Programming


Q3
Which of the following symbol is used to denote
processing part in a flowchart?
A. Oval
B. Rectangle
C. Diamond
D. Parallelogram

©LPU CSE101 C Programming


More practice questions on Flowchart
Write solutions using RAPTOR and without RAPTOR(Basic conventions)

1) Draw a flowchart to calculate circumference


of circle
2) Draw a flowchart to display the equivalent
grade student has achieved after calculating the
percentage of marks in 5 subjects[A+,A,Fail]
3) Draw a flowchart to calculate the area of
triangle, cylinder and rhombus
4) Draw a flowchart to calculate the compound
interest
©LPU CSE101 C Programming
©LPU CSE101 C Programming

You might also like