0% found this document useful (0 votes)
15 views10 pages

Chapter 11

An algorithm is a step-by-step procedure for solving problems or performing tasks, essential for programming as it clarifies the problem and organizes thoughts. The document provides examples of algorithms for various tasks, including adding numbers and making tea, highlighting the importance of identifying input, process, and output. Writing algorithms helps save coding time, reduces errors, and acts as a blueprint for coding.

Uploaded by

mpk5rks89x
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)
15 views10 pages

Chapter 11

An algorithm is a step-by-step procedure for solving problems or performing tasks, essential for programming as it clarifies the problem and organizes thoughts. The document provides examples of algorithms for various tasks, including adding numbers and making tea, highlighting the importance of identifying input, process, and output. Writing algorithms helps save coding time, reduces errors, and acts as a blueprint for coding.

Uploaded by

mpk5rks89x
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/ 10

Programming

Algorithm in Programming
What is Algorithm
• Definition:

An algorithm is a step-by-step procedure or set of instructions to solve


a problem or perform a task.

• Examples of algorithms in daily life:


• Making a cup of tea
• Tying shoelaces
• Following a recipe
Why Write an Algorithm Before
Programming?
Reasons:
• Helps you understand the problem clearly
• Organizes your thoughts logically
• Saves coding time and reduces errors
• Makes it easier to test and debug
• Acts as a blueprint for writing code
Algorithm Example 1
Problem: Write an Algorithm of a program for Adding two numbers and show the result
• Algorithm Steps:
• Start
• Get the first number
• Get the second number
• Add the two numbers
• Display the result
• End
Question : Write Input Process and Output of the program
Input Process Output

First number , Second number Add both numbers Sum


Algorithm Example 2
• Problem: Find the square of a number
• Algorithm Steps:
• Start
• Get a number
• Multiply the number by itself
• Display the result
• End
• Question : Write Input Process and Output of the program
Input Process Output
A number Multiply number × number Square of number
Algorithm Example 3
• Problem: Calculate the area of a rectangle
• Algorithm Steps:
• Start
• Get the length
• Get the width
• Multiply length × width
• Display area
• End
Input Process Output
Length, Width Multiply length × width Area of rectangle
Algorithm Example 4
• Problem: Check if a number is positive or negative
• Algorithm Steps:
• Start
• Get a number
• If number ≥ 0 → Positive
• Else → Negative
• Display result
• End

Input Process Output


A number Check if number is ≥ 0 or < 0 "Positive" or "Negative"
Real-Life Problem: Making a Cup of Tea

Write an algorithm for making a cup of tea. Before you start, you need to understand
the steps and identify what you need (input), what you will do (process), and what
you get in the end (output).

• Algorithm Steps:
• Start
• Boil water
• Add tea leaves or tea bag to a cup
• Pour hot water into the cup
• Add sugar and milk if needed
• Stir the tea
• Serve the tea
• End
Input-Process-Output Table

Input Process Output


• Water, Boil,

• tea leaves/tea bag, pour,

• cup, add,
A cup of ready tea

• milk, mix

• sugar
Summary

• An algorithm is essential before writing code


• It simplifies the planning process
• Helps identify Input, Process, Output
• Helps solving Real Life Examples

You might also like