The document discusses algorithms and flowcharts, emphasizing the importance of step order in algorithms and various methods for writing them, such as pseudocode and flowcharts. It covers key concepts like conditional branching, loops, and subroutines, providing examples for clarity. Additionally, it includes practical exercises for programming in Java, demonstrating algorithm implementation.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
52 views52 pages
Chap-04 Algorithm and Flowcharts
The document discusses algorithms and flowcharts, emphasizing the importance of step order in algorithms and various methods for writing them, such as pseudocode and flowcharts. It covers key concepts like conditional branching, loops, and subroutines, providing examples for clarity. Additionally, it includes practical exercises for programming in Java, demonstrating algorithm implementation.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 52
{
Chap-04 Algorithm and Flowcharts < Akshara Chavan >
... } Algorithms 01 It is a list of precise steps. The order in which these steps are carried out is always crucial to the way an algorithm works.
Algorithms can be written in many different
02 ways including everyday natural language, pseudocode, flowcharts or programming languages.
03 linear progression linear progression, that is the result of one statement is used in the statements that follow. key actions / common terms used in pseudocode: Inputting data: INPUT or READ outputting data: WRITE or PRINT } calculation: +, -, *, / » comparison: >,<,=, <> Setting values: 4.1.1 { .. Writing an algorithm
} .. { .. Input and output } .. Input and output
} .. { ..
Conditional branching
} .. Conditional branching
* Conditional branching means that certain statements are carried out depending on the value stored within a particular variable name. ● IF…THEN…ELSE ● CASE…ENDCASE. IF…THEN
} .. IF…THEN…ELSE
} .. Example-01
} Example-02 an exam system where if a student gains 75 or more marks, they are awarded a distinction; if they get between 60 and 74 marks, they are awarded a merit; between 40 and 59 marks the student is awarded a pass; otherwise, they fail the course.
} .. CASE…ENDCASE ... Example-01 Example-01 { ..
Loops
} .. Loops There are three ways a loop operates. 1. Count-controlled loop 2. Pre-condition loop 3. Post-condition loop { .. Concept of counting If a loop is to be repeated a certain number of times, it is usual to set up a counter.
} .. FOR…NEXT
} FOR…NEXT…STEP WHILE…ENDWHILE
} .. REPEAT…UNTIL
} .. REPEAT…UNTIL You may use another technique for finishing a loop. You can come out of a loop by inputting a rogue value (i.e. a value that is out of the ordinary). For example, supposing you needed to write an algorithm which added up a set of numbers. If all the numbers to be added consisted of numbers less than 100 you could end the loop by inputting a rogue value such as 999 as follows
} .. Procedures/subroutines { .. A subroutine is a sequence of algorithm statements that perform a specific task. This subroutine can then be used in other algorithms as and when needed.
} .. House builder who needs to know the area of the top part of a brick wall underneath the roof. He or she wants to calculate the number of bricks to be used. Such a house is shown in the figure below, with the area which needs to be calculated indicated as a red triangle. The other areas which would need to be calculated are rectangle shapes.
} { File handling
... } 4.2 { .. Flowcharts } .. Common flowchart symbols * Central heating system flowchart Practical exercise 05
Write a Java program to convert a binary
number into a hexadecimal number.
Input data:
Input a binary number: 10010
Expected output:
Hexadecimal value: D Tablet { mockup You can replace the image on the screen with your own work. Just right-click on it and select “Replace image”
} { Phone mockup You can replace the image on the screen with your own work. Just right-click on it and select “Replace image”
... } { .. This is a map Venus Venus is the second planet from the Sun Mercury Mercury is the closest planet to the Sun
Mars Despite being red, Mars is a very cold place .. } A timeline always works well
{ Venus is the second planet from the Sun Despite being red, Mars is a very cold place * Mercury is the Jupiter is the closest planet to biggest planet of the Sun them all } Infographics are useful
{ .. Mars Venus Mars is a Solar Venus is a red planet hot planet System Mercury Jupiter Mercury is Jupiter is a very small gas giant
} .. Practical exercise 06 Write a Java program to check whether Java is installed on your computer.
Expected output:
Java Version: 1.8.0_71
Java Runtime Version: 1.8.0_71-b15 Java Home: /opt/jdk/jdk1.8.0_71/jre Java Vendor: Oracle Corporation Java Vendor URL: http://Java.oracle.com/ Java Class Path: . Use tables to represent data
{ Team A Team B Team C Team D
Mercury 0.06 0.53 0.38 0.38
Mars 0.11 9.4 0.53 0.78
Saturn 95.2 1.16 9.4 1.16
} You can use this graph Gráfico
Mercury Mercury is the smallest planet Venus Venus has very high temperatures * Jupiter Saturn Jupiter is the Saturn is a gas biggest planet giant with rings
Follow the link in the graph to modify its data and then paste the new one here. For more info, click here Practical exercise 07
Write a Java program to reverse a string.
Input data:
Input a string: My dog’s name is
Ralph
Expected output:
Reverse string: hplaR si eman s‘god
yM Our team
{ .. * Sofia Hill Alex Harris You can speak a bit You can speak a bit about this person here about this person here
.. } Thanks! < Do you have any questions? > youremail@freepik.com +34 654 321 432 yourwebsite.com
CREDITS: This presentation template was created by
Slidesgo, and includes icons by Flaticon, and Slidesgo Flaticon
infographics & images by Freepik
Freepik
Please keep this slide for attribution
Alternative resources Here’s an assortment of alternative resources whose style fits the one of this template: ● Programmers concept with flat design Resources Did you like the resources on this template? Get them for free at our other websites:
Photos ● Html and css collage concept with person I ● Html and css collage concept with person II ● Html and css collage concept with person III ● Html and css collage concept with person IV ● Medium shot smiley woman at library ● Medium shot man holding notebook