Uploaded by Abdelrhman Salem

Lab3 (1)

advertisement
Introduction to Programming
LAB 3
FLOWCHARTS
Flowchart Symbols
Description
)Start/End(
)Input/Output(
)Process(
)Decision(
)Flow lines(
Symbol
Flowchart Problems
PL 3.1 Draw a flowchart for a program that
calculate the circumference and area of a circle
given the radius (r)
PL 3.1
Area= 2Πr2
Circumference =2Πr
Start
End
Print Area, Circumference
Read r
Flowchart PL 3.1
Start
Read r
Area= 2Πr2
Circumference =2Πr
Print Area,
Circumference
End
Flowchart Problems
PL 3.2 Draw a flowchart for a program that
calculate the interest value for the balance
PL 3.2
Interest=balance*rate
End
Read name, balance, rate
Print name, balance, interest
Start
PL 3.2 Flowchart
Start
Read name, balance, rate
Interest=balance*rate
Print name, balance, Interest
End
Flowchart Problems
PL 3.3 Write an algorithm and draw a
flowchart to convert the length in feet to
centimeter. (Feet=30cm)
PL 3.3 Algorithm
Step 1: Start
Step 2: Input Lft
Step 3: Lcm ← Lft x 30
Step 4: Display Lcm
Step 5: End
PL 3.3 Flowchart
Start
Read Input Lft
Lcm = Lft x 30
Print Lcm
End
Flowchart Problems
PL 3.4 Write the algorithm AND Draw a
flowchart for a program that determine a
student’s final grade. The final grade is
calculated as the average of four marks.
PL 3.4 Algorithm
Step 1: Start
Step 2: Input m1,m2,m3,m4
Step 3: grade← (m1+m2+m3+m4)/4
Step 4: Display grade
Step 5:End
PL 3.4 Flowchart
Start
Read m1,m2,m3,m4
grade=(m1+m2+m3+m4)/4
Print grade
End
Flowchart Problems
PL 3.5 Write an algorithm and draw a
flowchart that will read the two sides of a
rectangle and calculate its area.
PL 3.5 Algorithm
Step 1: Start
Step 2: Input W,L
Step 3: A← W *L
Step 4: Display A
Step 5:End
PL 3.5 Flowchart
Start
Read W,L
A=W*L
Print A
End
Flowchart Examples
PL 3.6 Draw a flowchart for a program that
calculate the quotient of two numbers
PL 3.6
Read num1
Is num2=0
Display Not Defined
yes
Start
End
Read num2
Display result
result=num1/num2
No
PL 3.6 Flowchart
Start
Read num1
Read num2
Is num2=0
N
result=num1/num2
o
Display result
End
yes
Display Not
Defined
Flowchart Examples
PL 3.7 Draw a flowchart for a program that
calculate the Sum of even numbers
PL 3.7
n=n+2
Is N>10
sum=0
Start
End
Sum=sum+n
Display sum
N=2
yes
No
PL 3.7
Start
sum=0
N=2
Sum=sum + n
n=n+2
yes
No
Is N>10
Display sum
End
Flowchart Examples
PL 3.8 Draw a flowchart for a program that
check whether character read from keyboard
is Z. If it is Z then print END, else read another
character.
PL 3.8
Step 1 : Start
Step 2 : Create variable C
Step 3 : Read C
Step 4 : Check if C = ‘Z’. If no goto step 3.
Step 5 : Print END
 Step 6: Stop
PL 3.8
Start
Declare C=0
Display
Read Csum
Is C=’Z’
yes
Print END
End
No
Assignment
Write an algorithm and draw a flowchart to
print the square of all numbers from 1 to 20
which is divisible by 3.
Draw a flowchart to calculate the sum and the
average of odd numbers from 1 to 50 which
is divisible by 3
Download