Date post: | 14-Dec-2015 |
Category: |
Documents |
Upload: | zachariah-kempe |
View: | 254 times |
Download: | 5 times |
Exercise (1)Exercise (1)
Example: Example: - Using Pseudo code, Write suitable algorithm: Using Pseudo code, Write suitable algorithm: - Calculate and print the average temperature, readings for the Calculate and print the average temperature, readings for the
degrees as the following T1, T2, T3. degrees as the following T1, T2, T3.
22
Input T1, T2, T3Input T1, T2, T3
avg= (T1 + T2 + T3)/3avg= (T1 + T2 + T3)/3
Print avg Print avg
Input T1, T2, T3Input T1, T2, T3
avg= (T1 + T2 + T3)/3avg= (T1 + T2 + T3)/3
Print avg Print avg
Input T1, T2, T3Input T1, T2, T3
Sum = (T1 + T2 + T3)Sum = (T1 + T2 + T3)
Avg = sum/3Avg = sum/3
Print avg Print avg
Input T1, T2, T3Input T1, T2, T3
Sum = (T1 + T2 + T3)Sum = (T1 + T2 + T3)
Avg = sum/3Avg = sum/3
Print avg Print avg
Flow chartFlow chartStart or Stop Program
Input or Output
Process, Calculate, Storage
Arrows determine the direction of the program's progress
Used to express logical operations or operations report (Condition)
Connection
Sum = T1+T2+T3
Flow chartFlow chart- Example : Example : - Using flow chart, Write suitable algorithm: Using flow chart, Write suitable algorithm: - Calculate and print the average temperature Calculate and print the average temperature
for the following readings T1, T2, T3. for the following readings T1, T2, T3. startstart
Input T1, T2, T3
Avg = sum/3
Print avg
stopstop
Input : : T1, T2, T3
Processing:
Sum = T1+T2+T3Avg = sum/3
Output:Avg = sum/3
Using pseudo code and flow chart to Using pseudo code and flow chart to write an algorithm. Enter number (X) write an algorithm. Enter number (X) and then find and print the value (Y), and then find and print the value (Y), as shown in the following equation: as shown in the following equation:
Y=(X-2)/X Y=(X-2)/X
Note:Note: (if X=0 enter value of X again) (if X=0 enter value of X again)
start
stop
Input X
Y=(X-2)/X
Print Y
If X=0 yes
No
Flow Chart
Pseudo code input X
process if x=0 Re-enter the new value of x because you can not divide by 0“
Y=(X-2)/X output Y
Sum= T1+T2+T3
Flow chartFlow chartExample: Example: - Using flow chart, Write suitable algorithm: Using flow chart, Write suitable algorithm: - Calculate and print the average Calculate and print the average
temperature. Readings as the following T1, temperature. Readings as the following T1, T2, T3. T2, T3.
- IF the average is greater than 15 print the IF the average is greater than 15 print the average, else print the weather is cold.average, else print the weather is cold.
startstart
inputT1, T2, T3
Avg = sum/3
Print avg
avg > 15
Print “cold”
StopStop
StartInput T1,T2,T3
Sum = T1+T2+T3
Avg = sum/3
If avg > 15 then
Print avg
Else
Print “cold” End if
end
No Yes
DiscussDiscuss
Write an algorithm using pseudo code and flow chart for the Write an algorithm using pseudo code and flow chart for the introduction of 3 degrees and find the average temperature and print introduction of 3 degrees and find the average temperature and print the "cool air“ if temperature less than 15, Print "moderate air” if the "cool air“ if temperature less than 15, Print "moderate air” if temperature between 15 and 25, and print “hot air” if the temperature between 15 and 25, and print “hot air” if the temperature not verify the previous conditions. temperature not verify the previous conditions.
77
AnswerAnswer: :
If avg<15
End End
YesNo
If avg<25Print cool YesNo
Print moderate Print hot
Using pseudo code and flow chart to write an algorithm to calculate Using pseudo code and flow chart to write an algorithm to calculate the area and perimeter of a rectangle.the area and perimeter of a rectangle.Note: the area of the rectangle = length × width.Note: the area of the rectangle = length × width.
Perimeter = 2*(length+width)Perimeter = 2*(length+width)
99
Using pseudo code and flow chart to write an algorithm to calculate and print Using pseudo code and flow chart to write an algorithm to calculate and print the area of a right-angled triangle .the area of a right-angled triangle .
The base of the triangle = aThe base of the triangle = a
The height of triangle= bThe height of triangle= b
Equation of area= (1/2)*a*bEquation of area= (1/2)*a*b
Write a program using the pseudo code and flow chart to Write a program using the pseudo code and flow chart to find the area of a circle which radius R print it.find the area of a circle which radius R print it.Note: The area of a circle is equal to π * RNote: The area of a circle is equal to π * R22, where π is a , where π is a constant value of approximately 3.14.constant value of approximately 3.14.
Input R Process Π = 3.14A= π × R × RoutputPrint AEnd
Pseudo code Pseudo code flow chart flow chart startstart
Input r
π × r × A= r
Print A
EndEnd
π = 3.14
Using the methods (pseudo code and flow chart), we need to find and Using the methods (pseudo code and flow chart), we need to find and print the vicinity of the football stadium, and determine whether print the vicinity of the football stadium, and determine whether international (greater than or equal to 600 m) or local (less so), international (greater than or equal to 600 m) or local (less so),
Note: The perimeter of the rectangle is equal to (length + width) × 2 .Note: The perimeter of the rectangle is equal to (length + width) × 2 .
StartInput L , W
C= 2× ( L + W) If c ≥ 600 then
Print “ international”
Else
Print “ local”End if print c End
flow chart flow chart
C= 2* (L+W)
startstart
Input L,W
Print Internationa
l
EndEnd
If C>=600Print LocalYesNo
Formulate resolve the matter to find the zakaah and that if you know money saver and you know that zakaah = 0.025 × money saver, provided the account of zakaah money if it exceeds 1000 SR
start
stop
Input M
K=M*0.025
Print k
M>1000 no
yes
Flow chart
Pseudo codeInput money mProcess If m>1000 calculate zakaah else do not calculate zakaahzakaah=0.025*moneyOutput print zakaah
Output: print output from 1 to 49Input: no inputProcess: transfer from odd number to odd number
no=1Print nono=no+2
If no>50 then stop else go to step (2)
start
stop
No=1
Print No
No=No+2
No>50no
yes
Pseudo code
Formulate a solution to print the odd numbers from 1 to 49 ?
Flow chart
Write a program that accept an integer from the user and print it is Positive or Negative number.
Write a program that accept an integer from the user and test the number . If it is positive print Positive, if it is negative print Negative if equal zero print equal zero.
start
Enter number (n)
n>0
N<0
Print “positive”
Print “negative ”
print “equal zero”
end
yes
yes
No
No
Use flow chart to write algorithm. Read an integer from the user and test then number . If it is positive print Positive, if it is negative print Negative if equal zero print equal zero.