3 flowcharts
TRANSCRIPT
8/7/2019 3 Flowcharts
http://slidepdf.com/reader/full/3-flowcharts 1/21
Basic Data Types(almost all P.Languages)
• int ---- integer – Whole number
• float ---- floating point – number with
decimal point• double ---- for bigger or larger
numbers with decimal point
• char - character – single letter, symbol,
or number enclosed commonly bysingle quotes
8/7/2019 3 Flowcharts
http://slidepdf.com/reader/full/3-flowcharts 2/21
Arithmetic Operators
Symbols Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus(Remainder)
8/7/2019 3 Flowcharts
http://slidepdf.com/reader/full/3-flowcharts 3/21
Hierarchy of Arithmetic Operator
MDAS RULE
FROM LEFT TO RIGHT
8/7/2019 3 Flowcharts
http://slidepdf.com/reader/full/3-flowcharts 4/21
Assignment Operator
= (single equal sign)
---- use to assign valueto a variable
8/7/2019 3 Flowcharts
http://slidepdf.com/reader/full/3-flowcharts 5/21
Relational Operators
Symbols Meaning
> Greater than
>= Greater than or Equal to
< Less than
<= Less than or Equal to
== Equal to
!= Not Equal to
8/7/2019 3 Flowcharts
http://slidepdf.com/reader/full/3-flowcharts 6/21
Logical Operator
Symbols Meaning
&& and
|| or
! not
8/7/2019 3 Flowcharts
http://slidepdf.com/reader/full/3-flowcharts 7/21
Logical Operator
A B Z = A&&B
0 0 0
0 1 0
1 0 0
1 1 1
A B Z = A||B
0 0 0
0 1 1
1 0 1
1 1 1
Logical AND(&&) Logical OR(||)
Logical NOT(!)
A Z = !A
0 1
1 0
8/7/2019 3 Flowcharts
http://slidepdf.com/reader/full/3-flowcharts 8/21
Programming Exercises
PROBLEMS
8/7/2019 3 Flowcharts
http://slidepdf.com/reader/full/3-flowcharts 9/21
Problem no.1
• Create a flowchart that calculates thesum of two input number and displaythe result.
• Algorithm
Input Process Output
Enter two
numbers (n1,n2)
Compute the sum
(sum = n1+n2)
Display the sum
(sum)
8/7/2019 3 Flowcharts
http://slidepdf.com/reader/full/3-flowcharts 10/21
start
stop
int n1
int n2int sum
Enter 1st no: _
Enter 2nd
no: _
sum = n1 + n2
THE SUM is sum
8/7/2019 3 Flowcharts
http://slidepdf.com/reader/full/3-flowcharts 11/21
Problem no.2
(single sided)
• Draw a flowchart that determines if theinput number is positive. Consider zeroas positive.
• AlgorithmEnter a number (n)
if(n>=0)
Display that the number is POSITIVE
8/7/2019 3 Flowcharts
http://slidepdf.com/reader/full/3-flowcharts 12/21
8/7/2019 3 Flowcharts
http://slidepdf.com/reader/full/3-flowcharts 13/21
Problem no.3
(double sided)
• Draw a flowchart that determines if theinput number is positive or negative.Consider zero as positive.
• AlgorithmEnter a number (n)
if(n>=0)
Display The number is POSITIVE
else
Display The number is NEGATIVE
8/7/2019 3 Flowcharts
http://slidepdf.com/reader/full/3-flowcharts 14/21
start
stop
int n
Enter a number
n: _
The number is
POSITIVEif(n>=0)
yesno
The number is
NEGATIVE
8/7/2019 3 Flowcharts
http://slidepdf.com/reader/full/3-flowcharts 15/21
Problem no.4
(multiple alternative)
• Draw a flowchart that determines if theinput number is positive or negative orneutral if the input number is zero.
• AlgorithmEnter a number (n)
if(n>0)
Display The number is POSITIVE
else if(n<0)
Display The number is NEGATIVE
else
Display The number is neutral
8/7/2019 3 Flowcharts
http://slidepdf.com/reader/full/3-flowcharts 16/21
start
stop
int n
Enter a number n:
_
The
number is
POSITIVE
if(n>0)
yes
no
The
number is
NEGATIVE
if(n<0)
The
number is
NEUTRAL
yesno
8/7/2019 3 Flowcharts
http://slidepdf.com/reader/full/3-flowcharts 17/21
Problem no.5(case control, similar with
multiple alternative)
• Draw a flowchart that displays anequivalent color once an input lettermatch its first letter. Consider the criteria
• Criteria
Letters Colors
B or b Blue
R or r Red
Y or y Yellow
Other letters Unknown
8/7/2019 3 Flowcharts
http://slidepdf.com/reader/full/3-flowcharts 18/21
start
stop
char l
Enter a letter l_
Case l
is
Case l is B or b
BLUE RED YELLOW
Unknown
Color
Case l is R or r Case l is Y or y
Case l is other letter
8/7/2019 3 Flowcharts
http://slidepdf.com/reader/full/3-flowcharts 19/21
Problem no.6(case control, similar with multiple alternative)
• Draw a flowchart that generates/displays the
given sequence of numbers.
Sequence nos.
1
2
3
4
5
8/7/2019 3 Flowcharts
http://slidepdf.com/reader/full/3-flowcharts 20/21
start
stop
int n = 1
n <=5 Display n
true
n++
8/7/2019 3 Flowcharts
http://slidepdf.com/reader/full/3-flowcharts 21/21
start
stop
int n = 1
Display n
true
n++
n == 6
a
a
false