0% found this document useful (0 votes)
1K views

Flow Chart Exercises

The document provides algorithms and flowcharts for solving three problems: 1) Adding two numbers and printing the sum 2) Finding the sum of 5 numbers by using a loop to iteratively add inputs 3) Printing "Hello World" 10 times by using a loop to repeatedly print and increment a counter.

Uploaded by

Ng Shi Qing
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views

Flow Chart Exercises

The document provides algorithms and flowcharts for solving three problems: 1) Adding two numbers and printing the sum 2) Finding the sum of 5 numbers by using a loop to iteratively add inputs 3) Printing "Hello World" 10 times by using a loop to repeatedly print and increment a counter.

Uploaded by

Ng Shi Qing
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Flow chart exercises

Q1. Add 10 and 20


To solve this problem, we will take a variable sum and set it to zero. Then
we will take the two numbers 10 and 20 as input. Next, we will add both the
numbers and save the result in the variable sum i.e., sum = 10 + 20.
Finally, we will print the value stored in the variable sum.

Algorithm (in simple English)


 Initialize sum = 0 (PROCESS)

 Enter the numbers (I/O)

 Add them and store the result in sum (PROCESS)

 Print sum (I/O)

Flowchart
Q2. Find the sum of 5 numbers
In this question we are asked to find the sum of 5 numbers. So, we will take
two variables - sum and count and set both of them to zero. The sum
variable will store the result while the count variable will keep track of how
many numbers we have read.

To solve this problem, we will use the concept of loop. In loop or iterative
operation, we execute some steps repeatedly as long as the given
condition is TRUE. In this case we will keep reading the input till we have
read 5 numbers.

So, we first initialize sum and count to zero. Then we will take the input and
store it in a variable n. Next, we will add the value stored in n to sum and
save the answer in sum.

i.e., sum = sum + n

Then we will increment count by 1 and check if count is less than 5. If this
condition is TRUE then we will take another input. If the condition is FALSE
then we will print the value stored in variable sum.

Algorithm (in simple English)


1. Initialize sum = 0 and count = 0 (PROCESS)

2. Enter n (I/O)

3. Find sum + n and assign it to sum and then increment count by 1


(PROCESS)

4. Is count < 5 (DECISION)


5. if YES go to step 2
else
Print sum (I/O)

Flowchart
Q3. Print Hello World 10 times
This problem is also solved using the loop concept. We take a variable
count and set it to zero. Then we print "Hello World" and increment count
by 1.

i.e., count = count + 1

Next, we check if count is less than 10. If this is TRUE then we again print
"Hello World" and increment the variable count. On the other hand if the
condition if FALSE then we will stop.

Algorithm (in simple English)


1. Initialize count = 0 (PROCESS)

2. Print Hello World (I/O)

3. Increment count by 1 (PROCESS)

4. Is count < 10 (DECISION)

5. if YES go to step 2
else Stop

Flowchart
1. A quadratic equation of a x 2 +bx+ c can be solved by equating the root, x, to be
x=−b ± √ b2−4 ac. Depending on √ b2−4 ac , there are three possibilities for x
(root):

b 2−4 ac = 0 è there is only one root

b −4 ac > 0 è there are two roots


2

b −4 ac < 0 è there is no root


2

Draw a flowchart that will read in values for a, b and c, and will display whether:

 There is only one root and print this root out


 There are two roots and print these two roots out
 There is no root for x
2. Draw a flowchart for this problem:

Read in grades with a value between 0 and 100 until a negative grade or grade
greater than 100 is read in. Stop the loop once a negative grade or when the
grade of more than 100 is read in. Then display the total sum of all the other
grades except for the last input (which is either negative or more than 100).

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy