Problem 1 : Use a flowchart to calculate the sum :
S =1 + + 2 + 3 + . + n where n is an
integer that is obtained from the user. Assume that n 0.
Problem 2 : Use a flowchart to calculate the expression :
+ 2 + 2 + . + 2
Objective : Given code (obtained from user), count the number of digits it has.
Variables : code, ndigits
Solution 1 :
A number larger than or equal to 0 and less than 10 has 1 digit (ndigits = 1)
A number larger than or equal to 10 and less than 100 has
Loop = Repetition Structure
= Block of instructions that are repeadtely executed until some
conditions are satisfied.
There are different possible loop structures :
block of inst
Post-Test Loop : "Execute THEN Check condition"
ECOR 1606 - Fall 2012
Trace/Execute a flowchart by reporting the values assigned to the variables
Correct/modify a flowchart
Write and Evaluate arithmetic expressions
Write and Evaluate logical expressions
Draw line/circle, calculate coordinates of points
A variable is a container destined to receive values (text, number .)
a) When using variables, you need
. a name MUST start with a letter
CAN be a combination of letters and numbers
CANNOT contain special characters (other than "_" )
Problem 1 : Write the logical expressions corresponding to the following individual cases:
(a) Given an integer n, check if n is divisible by 12 and if n is be less than 55
(b) Given an integer n, check if n is lies within the interval [15 ; 32
ECOR 1606 - Problems II (Selections)
Problem 1 : In some school, the marking scheme is set as follows:
When the final numerical grade is less than 50, the final grade is F
When the final numerical grade is at least 50 and less than 60, the final grade is
Input and Ouput
"Give me a number "
P UT "Here is the number you
provided " + n
An input gets a value (either a number or
a text) from the user. This instruction defines
a variable n, which is assigned whatever
the user enters.
An output d
Adding terms .
initialize the sum
index corresponding to first term
May need to initialize term to
some value before the loop
Number of terms to add to the sum
(could be an input)
One single term t
Minimizing a function
f x = x 2x 8 x 5x has a unique minimum on [ -2; 1]
Define a = -2 and b = 1 (lower and upper bound)
The method consists of starting at some initial value for x (for instance x = a), calculate y the value
of f at the po