Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Introduction to Algorithms and Flowcharts in Computer Science, Cheat Sheet of Computer Science

An introduction to algorithms, their representation using flowcharts and pseudocode, branching, and looping concepts in computer science. It includes examples and pseudocode for various algorithms, such as calculating employee payment, solving quadratic equations, and summing even numbers. The document also covers the use of loops and branching in algorithms, and includes an exercise for the reader to create a flowchart and pseudocode for a program that finds the largest of three numbers.

Typology: Cheat Sheet

2022/2023

Uploaded on 03/04/2024

khanh-xa-gia
khanh-xa-gia 🇻🇳

2 documents

1 / 17

Toggle sidebar

Related documents


Partial preview of the text

Download Introduction to Algorithms and Flowcharts in Computer Science and more Cheat Sheet Computer Science in PDF only on Docsity! Introduction to computer science 1 Chapter 1 INTRODUCTION TO ALGORITHMS AND FLOWCHARTS 2 Chapter 1  Algorithms  Using Flowchart to describe Algorithm  Algorithm in pseudo-code  Branching in Algorithms  Loop in Algorithms 5 Example 2.1. Calculate the payment of an employee Start Input Name, Hours, Rate Calculate Pay  Hours  Rate Dislay Name, Pay End Note: Name, Hours and Pay are variables in the program. Fig. 2. Example 2.2: Calculate the average of 3 numbers 6 Fig. 3. Example 2.3: How to compute profit and loss. 7 Fig. 4. Example 2.1 10 Pseudo-code of the program: Input A if A > 0 then calculate B = sqrt(A) print B else Print “ A is negative” endif Branching 11 Example 4.2: Solving the quadratic equation: ax2 + bx +c = 0 Pseudo-code of the program: Input a, b, c Calculate del = b2 + 4.a.c if del >0 then x1 = (-b + sqrt(del)/(2.a) x2 = (-b - sqrt(del)/(2.a) print x1, x2 else if del =0 then x = -b/(2.a) else print “No solution” endif 5. Loops on Algorithms  Many problems require repetition capability, in which the same calculation or sequence of instructions is repeated, over and over, using different sets of data.  Loop is a very important concept in programming.  Example 5.1. Write a program to do the task: Print a list of the numbers from 4 to 9, next to each number, print the square of the number. 12 Pseudo-code of Example 5.2 sum = 0 count = 1 do if count is even then sum = sum + count endif count = count + 1 while count <= 20 Display sum 15 Exercise 16 Give the flowchart of the program which finds the largest among three different numbers. Write the pseudo-code for the flowchart. Ans. Input a,b,c if a > b then if a > c then print a endif else if b > c then print b else print c endif endif 17
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved