0% found this document useful (0 votes)
11 views18 pages

Algorithm

An algorithm is a set of steps to complete a task and should include input, processing, and output. Good algorithms are clearly defined, unambiguous, and effective. The document discusses different ways to represent algorithms including pseudocode, flowcharts, and examples of algorithms to add numbers, find the largest of three numbers, and calculate a factorial.

Uploaded by

Paul Gutierez
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
0% found this document useful (0 votes)
11 views18 pages

Algorithm

An algorithm is a set of steps to complete a task and should include input, processing, and output. Good algorithms are clearly defined, unambiguous, and effective. The document discusses different ways to represent algorithms including pseudocode, flowcharts, and examples of algorithms to add numbers, find the largest of three numbers, and calculate a factorial.

Uploaded by

Paul Gutierez
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 18

Programming Algorithm

An algorithm is simply a set of steps used to


complete a specific task. They're the building blocks
for programming. Which should contain an Input,
Process and an Output.
Qualities of a Good Algorithm

• Input and output should be defined precisely.


• Each step in the algorithm should be clear and unambiguous.
• Algorithms should be most effective among many different ways to
solve a problem.
• An algorithm shouldn't include computer code. Instead, the algorithm
should be written in such a way that it can be used in different
programming languages.
Pseudocode
(pronounced SOO-doh-kohd) is a detailed yet readable
description of what a computer program or algorithm
must do, expressed in a formally-styled natural
language rather than in a programming language
Flowchart
a type of diagram that represents
an algorithm, workflow or process.
How to plan and draw a basic flowchart

• Define your purpose and scope.


• Identify the tasks in chronological order.
• Organize them by type and corresponding shape.
• Draw your chart.
• Confirm your flowchart.
Flowcharts can:

• Demonstrate the way code is organized.


• Visualize the execution of code within a program.
• Show the structure of a website or application.
• Understand how users navigate a website or program
Algorithm 1: Add two numbers entered by the user

• Step 1: Start
• Step 2: Declare variables Number1, Number2 and Sum.
• Step 3: Read values Number1 and Number2.
• Step 4: Add Number1 and Number2 and assign the result
to Sum.
• Sum←Number1+Number2
• Step 5: Display Sum
• Step 6: Stop
Algorithm 2: Find the largest number among three numbers

1. Start
2. Input A,B,C
3. If (A>B) and (A>C) then print “A is greater”.
Else if (B>A) and (B>C) then print “B is greater”.
Else print “C is greater”.
4. Stop
Algorithm 3: Find the factorial of a
number
• Step 1: Start
• Step 2: Declare Variable n, fact, i
• Step 3: Read number from User
• Step 4: Initialize Variable fact=1 and i=1
• Step 5: Repeat Until i>n
• 5.1 fact=fact*i
• 5.2 i=i+1
• Step 6: Print fact
• Step 7: Stop
Add two numbers entered by the user

• BEGIN
• NUMBER s1, s2, sum
• OUTPUT("Input number1:")
• INPUT s1
• OUTPUT("Input number2:")
• INPUT s2
• sum=s1+s2
• OUTPUT sum
• END
Find the largest number among three
numbers
• BEGIN
• NUMBER A,B,C
• INPUT A
• INPUT B
• INPUT C
• IF A>B AND A>C THEN
• OUTPUT A "is higher"
• ELSE IF B> C THEN
• OUTPUT B "is higher"
• ELSE
• OUTPUT C "is higher"

Find the factorial of a number
• Read number
• Fact = 1
• i=1
• WHILE i<=number
• Fact=Fact*i
• i=i+1
• ENDWHILE
• WRITE Fact
Add two numbers entered by the user
Find the largest number among three numbers
Data i factorial

6 1 1

2 1

3 2

4 6

5 24

6 120

7 720

You might also like